Jquery 第二个AJAX调用数据未定义
我有两个ajax JSON调用,第二个URL是从第一个URL传递的变量Jquery 第二个AJAX调用数据未定义,jquery,ajax,Jquery,Ajax,我有两个ajax JSON调用,第二个URL是从第一个URL传递的变量nextURL 第二个ajax函数将nextur变量注册为使用警报(nextur)测试的变量,但我没有得到任何数据。错误控制台声明$('#gameBoxleft').html(data.post.title)数据未定义 我不确定第二个ajax调用是否出错 // -------------- MAIN AJAX CALL FUNCTION -------------- function call_ajax(url, elem)
nextURL
第二个ajax函数将nextur变量注册为使用警报(nextur)
测试的变量,但我没有得到任何数据。错误控制台声明$('#gameBoxleft').html(data.post.title)代码>数据未定义
我不确定第二个ajax调用是否出错
// -------------- MAIN AJAX CALL FUNCTION --------------
function call_ajax(url, elem) {
$.ajax({
url: url,
method: "GET",
data: {json: 1},
dataType: "JSON"
})
// -------------- FUNCTIONS FOR AFTER AJAX DONE --------------
.done(function (data) {
// Append the box
appendBox(elem);
// LOAD GAMEBOX JSON DATA
$("#game-name").html(data.post.title);
$("#game-reels").html(data.post.custom_fields.reels);
$("#game-paylines").html(data.post.custom_fields.paylines);
$("#game-minBet").html(data.post.custom_fields.min_bet);
$("#game-maxBet").html(data.post.custom_fields.max_bet);
$("#game-jackpot").html(data.post.custom_fields.jackpot);
$("#game-info").html(data.post.custom_fields.game_info);
var nextURL = (data.previous_url) + "?json=1";
var prevURL = (data.next_url);
processTwo(nextURL);
});
}
// -------------- NEXT OBJEXT AJAX CALL FUNCTION --------------
function processTwo(nextURL) {
alert(nextURL);
$.ajax({
url: 'nextURL',
method: "GET",
data: {json: 1},
dataType: "JSON"
})
.done(function() {
$('#gameBoxleft').html(data.post.title);
});
}
您已经在'
中提到了nextURL
,其中它应该是从调用函数发送的参数,如下所示:
function processTwo(nextURL) {
alert(nextURL);
$.ajax({
url: nextURL, //This needs to be changed
method: "GET",
data: {json: 1},
dataType: "JSON"
})
.done(function() {
$('#gameBoxleft').html(data.post.title);
});
}
我认为你应该通过:
url: nextURL,
而不是:
url: 'nextURL',
在第二个ajax中,您将在变量中传递url:
此变量为:nextURL
从变量名称中删除配额标记:
$.ajax({
url: nextURL, //remove quota marks.
method: "GET",
data: {json: 1},
dataType: "JSON"
})
在这种情况下,变量的值将作为URL,否则,在URL:'nextURL'
中的变量内有配额标记,URL将被视为nextURL
,而不是URL。您还没有处理错误,因此它不会给出任何错误
您可以在浏览器控制台中检查错误。面部手掌瞬间
.done(函数(data)会有帮助!在url:'nextURL'
显示console.log(data)
??请你刚才让我做了facepalm,我没有在.done(函数)中传递数据这个问题已经被编辑过了,现在当我们看到答案时有点困惑……抱歉,会恢复到原来的状态。