Ajax 显示json返回的值
我有一个在html页面上显示数据的简单问题。下面的代码在屏幕上显示json数据数组。但是,我想通过每个元素来显示它,比如“url”、“img_url”等等。 你能告诉我是谁做的吗 ajax代码Ajax 显示json返回的值,ajax,json,Ajax,Json,我有一个在html页面上显示数据的简单问题。下面的代码在屏幕上显示json数据数组。但是,我想通过每个元素来显示它,比如“url”、“img_url”等等。 你能告诉我是谁做的吗 ajax代码 var dataString = 'url=' + pathname + '&img_name=' + img_name + "&tag=" + tag; $.ajax({ type: "POST", url: "image_finder.php",
var dataString = 'url=' + pathname + '&img_name=' + img_name + "&tag=" + tag;
$.ajax({
type: "POST",
url: "image_finder.php",
data: dataString,
dataType: 'json',
complete: function (xhr, status) {
if (status === 'error' || !xhr.responseText) {
//handleError();
alert("error");
} else {
var data = xhr.responseText;
$('#tt').html("<div id='message'></div>");
$('#message').html(data);
}
}
});
var-dataString='url='+pathname+'&img\u name='+img\u name+“&tag=“+tag;
$.ajax({
类型:“POST”,
url:“image_finder.php”,
数据:dataString,
数据类型:“json”,
完成:功能(xhr,状态){
如果(状态=='error'| |!xhr.responseText){
//handleError();
警报(“错误”);
}否则{
var data=xhr.responseText;
$('#tt').html(“”);
$('#message').html(数据);
}
}
});
json返回
{"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":""}
{cid:“14”,“url:“http:\/\/localhost\/”,“img\u url:“http:\/\/static.naver.net\/www\/up\/2013\/0305\/mat\/u 173330634c.jpg”,“img\u名称:“mat\\\\/\/localhost\/”,“html:“\r\n\r\n\r\n\r\nRefre\r\n\r\n\r\n\r\n\r\r\n”,“jscript”:
我希望这就是您所需要的。$.each(数据、函数(键、值){$('tt').html(“$”;('message')).html(键+”:“+value);});它打印出“1220:未定义”
$.ajax({
type: "POST",
url: "image_finder.php",
data: dataString,
dataType: 'json',
success: function (data) {
for(var item in data){
console.info(item);//print key
console.info(data[item]);//print value
}
}
});