jQuery AJAX,GET,POST JSON问题,似乎没有得到任何响应

时间:2011-08-13 05:24:03

标签: jquery ajax json

$.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+'" />&nbsp;');
    });
}

});

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”并以红色显示,就像找不到文件一样。

2 个答案:

答案 0 :(得分:3)

看看你得到的回应。

enter image description here

http://jsfiddle.net/praveen_prasad/tnaWd/

答案 1 :(得分:0)

尝试使用jQuery.getJSON() http://api.jquery.com/jQuery.getJSON/ 它可以运行跨域