Foreach Ajax Json-Jquery [英] Foreach Ajax Json - Jquery
本文介绍了Foreach Ajax Json-Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我
我有一个数组
{"stars":[["Chris Pine","Keira Knightley","Kevin Costner"]]}
我想做的是foreach星,我想将一个输入附加到div上,并且foreach星,它们在输入中的价值,这就是我到目前为止所要做的.
What i'm trying to do is foreach star i want to append a input to a div and foreach star with they're value inside the input this is what i've so far.
$.ajax({
type: "GET",
url: 'ajax/get_details.php',
data: {id: imdb_id},
dataType: 'json',
success: function(data) {
$.each(data.stars, function(i, star) {
$('#stars').append('<input type="text" id="star" value="'+star+'" />');
});
},
});
有人可以告诉我我在做什么错吗,谢谢
Can anyone tell me what i'm doing wrong please thanks
推荐答案
{"stars":["Chris Pine","Keira Knightley","Kevin Costner"]}
将其更改为以上内容.您当前在数组中有一个数组.
Change it to the above. You currently have an array inside an array.
或者
$.each(data.stars[0], function(i, star) {
$('#stars').append('<input type="text" id="star" value="'+star+'" />');
});
如果您希望外部数组中有多个数组,则必须执行嵌套循环
If you expect to have multiple arrays in the outer array you have to do nested loops
这篇关于Foreach Ajax Json-Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文