[英]JQuery ajax call returns json data - good. How do we grab each piece of data so query can act on it?
Doing an ajax call to a page to grab 5 pieces of data. 对页面进行ajax调用以获取5个数据。 3 images as filenames, 2 statuses as numbers 1/0.
3个图像作为文件名,2个状态作为数字1/0。 End game is to use this data to instruct jquery to change out 3 divs with the images as a result of the ajax call.
最终游戏是使用此数据来指示jquery由于ajax调用而将图片更改为3个div。 So am trying to get a grip on these items to hand them off to a function that will swap out these divs.
因此,我试图抓住这些项目,将其交给可以交换这些div的功能。 Issue thus far is grabbing the data pieces into a format whereby I can manipulate them.
到目前为止,问题在于如何将数据片段转换成一种我可以操纵它们的格式。 Values to vars....
vars的值...
Return data seems fine. 返回数据似乎很好。 Formatted correctly.
格式正确。 Actual return example:
实际回报示例:
[
{"optiontext" : "spin1", "optionvalue" : "brown_anna.jpg"},
{"optiontext" : "spin2", "optionvalue" : "crada_amberly.jpg"},
{"optiontext" : "spin3", "optionvalue" : "ginda_marlins.jpg"},
{"optiontext" : "SID", "optionvalue" : "1"},
{"optiontext" : "HOT", "optionvalue" : "1"}
]
Called by - and just outputting them as a list - How does one obtain this data in distinct pieces as vars for a future query image swap? 调用者-只是将它们作为列表输出-如何将这些数据以不同的形式作为var获取,以便将来进行查询图像交换?
dataType:"json",
success: function (data) {
var winns="<ul>";
$.each(data, function(i,n){
winns+="<li>"+n["optionvalue"]+"</li>";
});
winns+="</ul>";
$('#message').append(winns);
}
Any help greatly appreciated - its been days...... Does not have to be JSON data either. 任何帮助都将不胜感激-过去已经过去了……也不必是JSON数据。 At this point will try anything to get this charity project done.
在这一点上,将尽一切努力来完成这个慈善项目。
Do you mean something like: 您的意思是:
dataType:"json",
success: function (data) {
$("#div1").append($("<img/>").attr("src", data[0].optionvalue));
$("#div2").append($("<img/>").attr("src", data[1].optionvalue));
$("#div3").append($("<img/>").attr("src", data[2].optionvalue));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.