I am trying to figure out how to make an AJAX call with JQuery to multiple JSON objects in a URL where each JSON Object has embedded JSON. Here are a few of the JSON Objects from the URL (with some generic info):
{
"count": 5401,
"take": "2",
"page": 1,
"data": [{
"index": 0,
"id": 100,
"name": "Product Name 1",
"brand": "Brand 1",
"images": "imgurl1.jpg"
}, {
"index": 1,
"id": 101,
"name": "Product Name 2",
"brand": "Brand 2",
"images": "imgurl2.jpg"
}, {
"index": 2,
"id": 102,
"name": "Product Name 3",
"brand": "Brand 3",
"images": "imgurl3.jpg"
}, {
"index": 3,
"id": 103,
"name": "Product Name 2",
"brand": "Brand 4",
"images": "imgurl4.jpg"
}]
}
So, do I need to split the JSON objects up at the comma that separates them, add them all to an array, and then make the AJAX call? Or can I make the call with the embedded JSON without the extra steps?
Here is the JQuery I have but it is not working:
$(document).ready(function(){
$.ajax({
type: 'GET',
data: { format: 'json' },
dataType: 'jsonp',
url: 'JSON url',
success: function(result) {
$.each(result.data, function(key, value){
$.each(value.data, function(k, v){
$('#stage').html('<p>Product ID: ' + result.id + '</p>');
$('#stage').append('<p>' + result.name + '</p>');
$('#stage').append('<p>' + result.brand + '</p>');
$('#stage').append('<img src="' + result.images + '" alt="' + result.brand + ' ' + result.name + '" /><br/>');
});
});
}
});
});