Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

JSON on page load

Avatar

Level 5

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?

1 Accepted Solution

Avatar

Correct answer by
Level 5

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.

 

View solution in original post

3 Replies

Avatar

Community Advisor

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.

Avatar

Level 5
@Ravi_Pampana - The JSON property is available in jcrcontent node of the page and it is not in any of the component's node.

Avatar

Correct answer by
Level 5

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.