javascript - How to parse json response in jQuery mobile? -
i new jquery mobile. trying contact name contacts. json sending ajax request. not getting alert when click on submit button.
my jquery ajax request
$(document).ready(function() { //after button clicked download info $("#submit").click(function(){ //start ajax request $.ajax({ url: "myurl/contacts.json", datatype: "json", success: function(data) { var json = $.parsejson(data); alert(json.name); }); }); }); contacts.json
{ "contacts": [ { "id": "c200", "name": "ravi tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, { "id": "c201", "name": "johnny depp", "email": "johnny_depp@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, . . . . ] }
how generate dynamic clickable list above ajax response?
datatype: "json"
already specifies returned info json object. read values, can utilize object syntax:
success: function(data) { //cycle trough returned "contacts": for(var i=0;i<data.contacts.length;i++){ console.log(data.contacts[i].name); } } javascript jquery ios ajax json
No comments:
Post a Comment