jQuery JSON 调用返回 null
我正在使用 jQuery 调用 JSON 源,如下所示:
{
total: 1,
current: 0
}
下面的 jQuery 脚本从 json 调用返回 NULL,我不明白为什么?数据源正确且有效。
$.ajax({
url: source,
cache: false,
beforeSend: function(){
target.before('<div class="feed-loading"></div>', function(){
target.slideUp();
});
},
success: function(html){
/* load feed data into target */
target.html(html).slideDown();
$('.feed-loading').fadeOut();
/* updates attendances */
$('.actionpanel a.attend').each(function(index) {
var event_id = $(this).attr('rel');
/* find if logged in user is attending */
$.getJSON(settings.base_url + 'ajax/event_attendance/' + event_id, function(attendance) {
console.log(attendance);
/* update attendance figures on page */
$('a.attend[rel="' + event_id + '"]').nextAll('.meta').text(attendance.total + ' attending');
if (attendance.current == 1) {
$('a.attend[rel="' + event_id + '"]').addClass('selected').attr('title', 'You are attending!');
};
});
});
}
});
我认为这一定与它在另一个 ajax 调用中的事实有关,因为我在其他地方使用过类似的代码并且它工作正常。
I am calling a JSON source with jQuery that looks like this:
{
total: 1,
current: 0
}
My jQuery script below is returning NULL from the json call and I can't work out why? The data source is correct and working.
$.ajax({
url: source,
cache: false,
beforeSend: function(){
target.before('<div class="feed-loading"></div>', function(){
target.slideUp();
});
},
success: function(html){
/* load feed data into target */
target.html(html).slideDown();
$('.feed-loading').fadeOut();
/* updates attendances */
$('.actionpanel a.attend').each(function(index) {
var event_id = $(this).attr('rel');
/* find if logged in user is attending */
$.getJSON(settings.base_url + 'ajax/event_attendance/' + event_id, function(attendance) {
console.log(attendance);
/* update attendance figures on page */
$('a.attend[rel="' + event_id + '"]').nextAll('.meta').text(attendance.total + ' attending');
if (attendance.current == 1) {
$('a.attend[rel="' + event_id + '"]').addClass('selected').attr('title', 'You are attending!');
};
});
});
}
});
I think it must be something to do with the fact its within another ajax call as I have used similar code elsewhere and its worked ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的 JSON 很糟糕——你缺少一个逗号。试试这个:
I think your JSON is bad -- you're missing a comma. Try this: