0

我不知道为什么我的代码没有在屏幕上打印键和值。警报消息是“[对象错误]”。

你能告诉我如何在屏幕上打印键和值巴黎吗?

索引.html

<script>
$.ajax({
       type: "POST",
       url: "image_finder.php",
       data: dataString,
       dataType: 'json',
       error:function(xhr,status,e){       
            alert('Error');
       },
       success: function(data) {
         $.each(data, function(key, val) {
            alert(key); // problem 
         });


       },
       error:function(xhr, status, error) {
           alert(error);
       }

    });
</script>

json返回

test{"tags":[{"cid":"14","url":"http:\/\/localhost\/","img_url":"http:\/\/static.naver.net\/www\/up\/2013\/0305\/mat_173330634c.jpg","img_name":"mat_173317134c.jpg","html":"<div id=\"hotspot-19\" class=\"hs-wrap hs-loading\">\r\n<img src=\"http:\/\/static.naver.net\/www\/up\/2013\/0305\/mat_173330634c.jpg\">\r\n<div class=\"hs-spot-object\" data-type=\"spot\" data-x=\"95\" data-y=\"64\" data-width=\"30\" data-height=\"30\" data-popup-position=\"left\" data-visible=\"visible\" data-tooltip-width=\"200\" data-tooltip-auto-width=\"true\">\r\nasdf\r\n<\/div>\r\n<div class=\"hs-spot-object\" data-type=\"spot\" data-x=\"168\" data-y=\"53\" data-width=\"30\" data-height=\"30\" data-popup-position=\"left\" data-visible=\"visible\" data-tooltip-width=\"200\" data-tooltip-auto-width=\"true\">\r\nrere\r\n<\/div>\r\n<\/div>\r\n","jscript":""}]}
4

1 回答 1

-1

您正在返回无效的 JSON image_finder.php- 寻找一个流浪者print 'test';echo 'test';image_finder.php.

您可以使用http://jsonlint.com/之类的服务来验证从后端脚本返回的 JSON。当 JSON 无效时,jQuery 会出错,这就是为什么 Alert 消息是[Object Error]

于 2013-03-07T02:21:45.653 回答