Error in splitting data from Ajax JSON format |
[eluser]Unknown[/eluser]
I'm a mobile application developer , we need an Technical Help in JSON (JavaScript Object Notation) , Here we need to get data from server in JSON format . we can able to view the response from server using Firebug .. But we find the Error (Undefined ) while splitting the JSON format array to individual String .but we can able to split from local workspace .we worked varied method to solve it. we need a guidance to that method . For Example : sample Json Format from http://qa-find.uglii.com/Home/GetCou...8c31b6a84.json [{"i":"W07O5auPxEuqPchXazzI_g","n":"Afghanistan"},{"i":"IjdD3Z-fO0uACOVRhyUBmw","n":"Aland Islands"},..... etc ] Response in JSON format as Above , we need to split into individual String such as var country1 = Afghanistan ; var country2 = Aland Islands; my code is ---------------------------------------------------------------------------------- var url = "js/test.json"; //var url = "http://qa-find.uglii.com/Home/GetCountries/9a3d0a019-e523-487f-8250-fd98c31b6a84.json"; //Actual Json Url link is url = "http://qa-find.uglii.com/Home/GetCountries/9a3d0a019-e523-487f-8250-fd98c31b6a84.json" // sample Json Url Link is url = "js/test.json" $.ajax({ url: url, contentType: "application/json; charset=utf-8", dataType: "script", type: "GET", cache: false, processData: false, error: function (xhtr, response, e) {}, success: function (jsonData, status) { var jo = eval(jsonData); // error at jo.length as undefined for (var i = 0; i < jo.length; i++) { $("#addoptions").append('<option name='+jo[i].i+>'+jo[i].n+'</option>'); } } }); ----------------------------------------------------------------------------------------
[eluser]vitoco[/eluser]
You don't need to "eval" the response, cause if you specify json as dataType it return a json object from jquery $.ajax man page Quote:dataTypeString Code: $.ajax({ Saludos |
Welcome Guest, Not a member yet? Register Sign In |