I have the following JSON that I receive from a URL, we call the URL here www.blabla.com/testjson
And it returns:
[{"Identifier":1,"Naam":"NOT Given","Adres":"Kopenhagen 9","Postcode":"0000LL","Plaats":"NOT Given","Longitude":"0.00000","Latitude":"0.00000"},
{"Identifier":2,"Naam":"NOT Given","Adres":"NOT Given 1","Postcode":"0000LL","Plaats":"Rotterdam","Longitude":"0.00000","Latitude":"0.00000"},
{"Identifier":3,"Naam":"NOT Given","Adres":"NOT Given 6","Postcode":"0000LL","Plaats":"Rotterdam","Longitude":"0.00000","Latitude":"0.00000"},
{"Identifier":4,"Naam":"NOT Given","Adres":"NOT Given 1","Postcode":"0000LL","Plaats":"Den Haag","Longitude":"0.00000","Latitude":"0.00000"},
{"Identifier":5,"Naam":"NOT Given","Adres":"NOT Given 218","Postcode":"0000LL","Plaats":"Zoetermeer","Longitude":"0.00000","Latitude":"0.00000"}
];
I want to retrieve this JSON en return this result, but I get UNDEFINED, this is my code:
$.each("www.blabla.com/testjson", function(index, element) {
$('.result').append(element.Naam);
alert(element.Naam);
});
You also need to check if the user cookies are true or else it won’t return something, I don’t do this because I work with phonegap and jquery mobile. Can that be the problem?
Try using the method
$.getJSON:For more information, check the online doc: http://api.jquery.com/jQuery.getJSON/
PS: Make sure that you added the website
www.blabla.comto your whitelist exception.For more information about Phonegap whitelist exceptions, check the online doc (the following link is for Phonegap / Cordova version 2.1.0): http://docs.phonegap.com/en/2.1.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide