我有这个功能
function getAllDays(year,month){
var getdate = new Date(); //Used to prevent caching during ajax call
$.getJSON("AantalUrenAjax?_d" +(new Date().getTime()) +"&jaar=" + year + "&maand=" + month ,function(data)
{
$.each(data, function(index, value)
{
windows.alert(('#Dag').val(value.Maand));
});
});
ajax调用给我的JSON是:
[{"Dag":"2013","Maand":"10","Jaar":"01","aantalafspraken":0},
{"Dag":"2013","Maand":"10","Jaar":"02","aantalafspraken":0},
{"Dag":"2013","Maand":"10","Jaar":"03","aantalafspraken":0},
]
如何检索值?
windows.alert(('#Dag').val(value.Maand));
崩溃:(
答案 0 :(得分:3)
我认为应该更像这样吗?
$.each(data, function(index, value) {
console.log(value.Maand);
});
答案 1 :(得分:3)
您的代码中存在一些语法错误。您的函数顶部有一个迷路v
,windows.alert
应为window.alert
。你错过了jQuery调用前的$
。您还要提醒您正在设置值的jQuery对象,而不是值本身。你可能想要:
window.alert(value.Maand);
$('#Dag').val(value.Maand);
答案 2 :(得分:0)
$.each(data, function(index, value) {
dagValue = value.Dag; // dagValue will be "2013"
maandValue = value.Maand; //maandValue will be "10"
...