jquery - Read JSON data in JavaScript -


i have method in controller returns json data.

public jsonresult data() {     return json(model, jsonrequestbehavior.allowget); } 

now how read , store above returned data using jquery? trying belwo

$("#btn").click(function () {     $.getjson("controller/data", function(result) {            alert(result.name + " ");     }); }); 

data returned

it returns multiple list,which has multiple items

eg : [0] {mylist} , has name,region etc      [1] {mylist} , has name,region etc 

from of returned json, returning array of objects. access these can use index of object within array. example:

$.getjson("controller/data", function(result) {     console.log(result[0].name); }); 

alternatively, can loop through returned items:

$.getjson("controller/data", function(result) {     (var = 0; < result.length; i++) {         console.log(result[i].name);     } }); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -