You say you are using jQuery but the signate for the success callback of an ajax operation is:
success(data, textStatus, jqXHR)
If you were returning a list of object the the data parameter would typically be an array assuming a json structure of something like:
[{id:1},{id:2},{id:3}]
You'd handle it like you would any other array, a for loop (or forEach or jQuery.each)
for(var i = 0; i<data.Length;i++){
var id = data[i].id;
//do something else
}
As I don't know how your html structure would function with your list of items i'm not sure how to advise specifically how to handle the array contents. Are you wanting to display a list of links?
-- Sam Critchley
"Wise man say 'forgiveness is divine, but never pay full price for late pizza." - TMNT
InternetReta...
Member
151 Points
171 Posts
Parse Returned Generic List of Objects in JQUERY
Apr 24, 2012 01:44 PM|LINK
At the moment my web service returns a simple object to a JQuery AJAX call, and I parse the result using:
function OnSuccess(response) {
if (response != null && response.d != null) {
var data = response.d;
if (data.Link.length > 0) {
$("#lnkExternal").attr("href", data.Link);
document.getElementById("btExternal").style.display = "block";
$("#btExternal").css('cursor', 'pointer');
}
}
}
I want to return a generic list of the same simple objects, how could I parse those in a loop?
Any help most appreciated.
worldspawn[]
Contributor
6081 Points
1336 Posts
Re: Parse Returned Generic List of Objects in JQUERY
Apr 24, 2012 03:50 PM|LINK
You say you are using jQuery but the signate for the success callback of an ajax operation is:
success(data, textStatus, jqXHR)
If you were returning a list of object the the data parameter would typically be an array assuming a json structure of something like:
[{id:1},{id:2},{id:3}]
You'd handle it like you would any other array, a for loop (or forEach or jQuery.each)
for(var i = 0; i<data.Length;i++){
var id = data[i].id;
//do something else
}
As I don't know how your html structure would function with your list of items i'm not sure how to advise specifically how to handle the array contents. Are you wanting to display a list of links?
"Wise man say 'forgiveness is divine, but never pay full price for late pizza." - TMNT
software development
asteranup
All-Star
30184 Points
4906 Posts
Re: Parse Returned Generic List of Objects in JQUERY
Apr 25, 2012 10:36 AM|LINK
Hi,
Check this post-
http://forums.asp.net/p/1682457/4426122.aspx/1?Re+JQuery+watermark+plugin+conflicts+with+autocomplete
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
InternetReta...
Member
151 Points
171 Posts
Re: Parse Returned Generic List of Objects in JQUERY
Apr 30, 2012 10:12 AM|LINK
Thanks for your help guys, it pointed me in the right direction.
This link has the most comprehensive answer:
http://elegantcode.com/2009/05/04/jquery-ajax-with-class-arrays/