Я не знаю, почему мой код не печатает ключ и значения на экране. Предупреждающее сообщение: «[Ошибка объекта]».print json values from Ajax return
Не могли бы вы рассказать мне, как печатать ключ и значение paris на экране?
index.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":""}]}
, если ваш «json return» - это данные об успехе, скорее всего вы хотите сделать $ .each() в массиве, а не на объект данных, который будет равен $ .each (data.tags, function (...) {...}) –