【发布时间】:2017-05-04 13:04:58
【问题描述】:
所以我目前正在开发这个网站应用程序,我正在尝试使用来自大学网站和 AJAX 的 JSON 来显示我的大学中有多少 PC 可用。我无法弄清楚,但它显示了第一个房间的所有 MAC,然后它对其他房间说未定义,它都是一个代码块,所以我看不出它哪里出错了,任何建议都会很棒。
JS:
var container = $('div.container');
$('input#get').click(function(){
$.ajax({
type: 'GET',
url: '(mylink)',
dataType: 'jsonp',
success: function(data) {
$.each(data, function(index, item) {
$.each(item, function(key, value) {
container.append('<div class="pcsinside">' + value.displayName + '</div>' + 'PCs available:' + ' ' + value.availPCs + ' ' + 'out of' + ' ' + value.numPCs + '<br/>' + 'Macs available:' + ' ' + value.availMacs + ' ' + 'out of' + ' ' + value.numMacs + '<br/>');
});
});
}
});
})
HTML:
<div class="container">
<div id="form-area">
<input id="get" type="submit" value="Press For PC Availability">
</div>
<div class="pcsinside">
</div>
</div>
这就是它的样子,每当 PC 更改 PC 和 MAC(未定义的 MAC 除外)时,它都会更新。
它适用于第一个,但不适用于其他 MAC,这是怎么回事?任何帮助将不胜感激,谢谢大家。
【问题讨论】:
-
value.availMacs 不正确,请检查您的 json 响应
-
先用console.log查看数据和item,这里也提供数据json
标签: jquery html json ajax undefined