$.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+'" /> ');
});
}
});
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"}]}
我可以告诉JSON是有效的。如果我对字符串进行硬编码,那么代码就可以正常工作了。$ .each()。然而,尝试通过post从URI获取JSON或在Firebug中获取我的响应是“200 OK”并以红色显示,就像找不到文件一样。