I have be writing code for Json requests, but haven't seen this before..
How do I go about it?
I want to return all the countries with their name and Phonecode
Here is the Json am getting request from:
data.json:
{
"af": {
"name": "Afghanistan",
"phoneCode": "93"
},
"al": {
"name": "Albania",
"phoneCode": "355"
},
"dz": {
"name": "Algeria",
"phoneCode": "213"
},
"ad": {
"name": "Andorra",
"phoneCode": "376"
}
}
I want it to return this:
Html:
<div id="results"></div>
Javascript:
<script>
$(document).ready(function() {
//start ajax request
$.ajax({
url: "data.json",
success: function(data) {
var json = $.parseJSON(data);
$('#results').html('Country: ' + json.[0].name);
}
});
});
});
</script>
Thanks!