Consume json data using Jquery -
i have webmethod in .cs page returns list.
this returns json this..
{ "d": [ "saint clair", "jefferson", "shelby", "tallapoosa", "blount", "talladega", "marshall", "cullman", "bibb", "walker", "chilton", "coosa", "clay", "tuscaloosa", "hale", "pickens", "greene", "sumter", "winston" ] }
and jaquery method is
$.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: strurl, data: "{'stateid':'" + stateid + "'}", async: false, success: function (response) { var obj = jquery.parsejson(response); alert(obj.d[0]); } })
i want loop through json data in jquery , values in json data.
since have json response server, can use datatype: 'json'
in ajax request. use $.each() iterate through array
$.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: strurl, data: "{'stateid':'" + stateid + "'}", async: false, datatype: 'json', success: function (response) { $.each(response, function(idx, value){ alert(value) }); } })
Comments
Post a Comment