Reputation: 33988
This is the first time I work with JSon, so pls dont be rude with me :)
I have this website. http://msdn.microsoft.com/en-us/library/jj164022(v=office.15).aspx
and this javascript sample:
jQuery.ajax({
url: http:// site url/_api/web/lists,
type: "GET",
headers: {
"ACCEPT","application/json;odata=verbose",
"Authorization", "Bearer " + accessToken
},
})
The thing is I have a div called results and I would like to show the list names that the rest service returns me.
Upvotes: 0
Views: 6893
Reputation: 458
See jQuery official documentation:
http://api.jquery.com/jQuery.ajax/
There are a lot of examples.
EDIT
If your call return one serializable object you can do something like this:
$.ajax({
url: http:// site url/_api/web/lists,
type: "GET",
headers: {
"ACCEPT","application/json;odata=verbose",
"Authorization", "Bearer " + accessToken
},
success: function(data) {
$.each(data, function(index, elem){
//... do some work where ...
alert(elem);
});
}
});
Upvotes: 2
Reputation: 2885
It's hard to say exactly how to show the list in your div without knowing how the returned JSON is formatted. But the main idea is that you'll need to add a success callback function to your jQuery.ajax() call in which you parse the returned data and insert it into your div. For example:
jQuery.ajax({
url: "http://siteurl/_api/web/lists",
type: "GET",
headers: {
"ACCEPT","application/json;odata=verbose",
"Authorization", "Bearer " + accessToken
},
success: function(data) {
var listTitle = data.title; // just an example; not sure if this property exists in your data
$("$myDiv").append('<p>' + listTitle + '</p>');
}
});
Upvotes: 1