javascript - How to read JSONP response data in name and value pairs in Jquery ajax.? -


i trying read json file other domain jsonp technique

here json

callback({   "response":{"docs":[       {         "firstname":"qwe",         "lastname":"asd",         "age":"30"},       {         "firstname":"zxc",         "lastname":"bnm",         "age":"40"},          .         .         .       {         "firstname":"poi",         "lastname":"lkj",         "age":"20"},       ]}, }) 

here jquery code

$.ajax({                     type: "get",                     url: "http://qqq.com/",                     crossdomain: true,                     jsonpcallback: 'callback',                     contenttype: "application/json; charset=utf-8",                     datatype: "jsonp",                     success: function (msg) {                          $.each(msg.response.docs, function (key, value){                               alert(key +"is"+value);                     }          }); 

from above code expecting alert output

firstname qwe lastname asd  , on 

but getting alert as

0 [object object] 1 [object object] , on 

can know need out put expectation like

firstname qwe lastname asd  

thanks in advance

your $each function iterating on docs array. parameters passed be:

  • key: index of doc object
  • val: doc object itself

instead, want iterate on every (key, value) pair loop:

success: function (msg) {   $.each(msg.response.docs, function (index, doc){       $.each(doc, function (key, val) {         console.log(key + 'is' + val);       });   } } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -