簡體   English   中英

第二個AJAX通話數據未定義

[英]Second AJAX call data undefined

我有2個Ajax JSON調用,第二個URL是從第一個傳遞過來的變量nextURL

第二個ajax函數注冊了一個用Alert(nextURL)測試的NextURL變量,但是我沒有任何數據。 錯誤控制台指出$('#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"
})

在這種情況下,variable的值將作為URL,否則,在url: 'nextURL'變量中帶有配額標記url: 'nextURL' ,該URL將被視為nextURL ,而不是URL。 而且您還沒有處理錯誤,因此不會給出任何錯誤。

您可以在瀏覽器控制台中檢查錯誤。

面對手掌的時刻。

.done(function( data )會有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM