Reputation: 36947
$.ajax({
type: 'POST',
dataType: 'json',
url: "http://domainsvault.com/test.json",
error: function(){alert('An unexpected Error occured while processing the resquest, reload the page to try again');},
timeout: 7200,
success: function()
{
document.write('<div style="background:#FFF;color:#000;height:12px;padding:10px" id="info"></div>');
$.each(data.items, function(i, item)
{
//document.write('<img src="'+item.image_url+'" border="0" onClick="alert(\''+item.description+'\')" /><br />');
document.write('<img src="'+item.image_url+'" border="0" class="imginfo" rel="'+item.description+'" alt="'+item.name+'" /> ');
});
}
});
the JSON http://domainsvault.com/test.json
{"items":[{"name":"hamburger","description":"A two-patty cheeseburger","image_url":"http://www.rw-designer.com/icon-view/5734.png"},{"name":"hot dog","description":"A hot dog with mustard","image_url":"http://www.rw-designer.com/icon-view/5735.png"},{"name":"pizza","description":"Pepperoni pizza","image_url":"http://www.rw-designer.com/icon-view/5743.png"},{"name":"ice cream","description":"Soft-serve ice cream","image_url":"http://www.rw-designer.com/icon-view/5739.png"},{"name":"fountain drink","description":"Ice cold drink","image_url":"http://www.rw-designer.com/icon-view/5741.png"}]}
Far as I can tell the JSON is valid. The code is working if I hardcode the string it works fine for the $.each(). However attempting to get the JSON from the URI via post or get my response in Firebug is "200 OK" and shows it in red as if the File wasn't found.
Upvotes: 0
Views: 5799
Reputation: 32117
Look at the response you are getting.
http://jsfiddle.net/praveen_prasad/tnaWd/
Upvotes: 3
Reputation: 5912
try using jQuery.getJSON()
http://api.jquery.com/jQuery.getJSON/
it can run cross domain
Upvotes: 0