JSON on page load

Avatar

Avatar
Validate 10
Level 2
v1101
Level 2

Likes

4 likes

Total Posts

150 posts

Correct reply

0 solutions
Top badges earned
Validate 10
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile

Avatar
Validate 10
Level 2
v1101
Level 2

Likes

4 likes

Total Posts

150 posts

Correct reply

0 solutions
Top badges earned
Validate 10
Validate 1
Ignite 1
Give Back 5
Give Back 3
View profile
v1101
Level 2

26-10-2020

Hello Community - I have a property that is having a JSON value in the page's jcr:content. Basically, I wanted to load the JSON on the page load. Can someone provide the best approach to load the JSON?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 4
Sandeep6
Level 4

Likes

56 likes

Total Posts

66 posts

Correct reply

15 solutions
Top badges earned
Validate 1
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 4
Sandeep6
Level 4

Likes

56 likes

Total Posts

66 posts

Correct reply

15 solutions
Top badges earned
Validate 1
Give Back
Boost 50
Boost 5
Boost 3
View profile
Sandeep6
Level 4

26-10-2020

Hi @v1101 ,

 

you can write a servlet and in that you can call a particular node using resource api.

Once you got the node as a resource, it is very easy to read particular property of that node using value map.

Now you can call the servlet on page load using jquery.

Please see below for sample code.

 

Resource resource = resolver.getResource("/content/sita/en_UK/x/y/jcr:content/"); 

$.ajax({
type: 'GET',
url:'/bin/sitea/servleta',
processData: false,
contentType: false,
data:formData,
success: function(msg){
alert("json");

}
});
}

 

Thanks,

Sandeep.

 

Answers (1)

Answers (1)

Avatar

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile
Ravi_Pampana
MVP

26-10-2020

Hi,

 

We can use Java-Use api or Javascript-use api to read json from the node and display in component html.

 

You can refer http://aemcorner.blogspot.com/2015/09/render-json-data-using-sightly-custom.html for example.