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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -