简体   繁体   English

AJAX中的AJAX导致意外的令牌错误

[英]AJAX within AJAX caused an Unexpected token error

I'm trying to do an AJAX call within a successful AJAX call. 我正在尝试在成功的AJAX调用中进行AJAX调用。 I looked at similar threads to see if I was doing it correctly and it seems like I am. 我看着类似的线程,看我是否做得正确,好像我在做。

What am I missing? 我想念什么? I'm getting an 'unexpected token error' at the start of the second '.ajax({' line. 我在第二个'.ajax({')行的开头收到“意外令牌错误”。

$.ajax({
            type: "POST",
            url: "actionPages/billing.php",
            data: {
                custID: custID,
                credFName: credFName,
                credLName: credLName,
                credNum: credNum,
                credExpireMonth: credExpireMonth,
                credCVVNum: credCVVNum,
                credAddress: credAddress,
                credStreet: credStreet,
                credCity: credCity,
                credProvinState: credProvinState,
                credCountry: credCountry,
                credPostalZip: credPostalZip,
                credExpireYear: credExpireYear,
                dealID: dealID
            },
            dataType: 'json',
            success: function(response) {

                var credID = response;

                .ajax({
                    type: "POST",
                    url: "actionPages/order.php",
                    data: {
                        credID: credID,
                        custID: custID,
                        dealID: dealID
                    },
                    dataType: 'json',
                    success: function(response) {

                    },
                    error: function (e) { console.log(e); }
                });
            },
            error: function (e) { console.log(e); }
        });

You are missing an $ in front of the second ajax call. 您在第二个ajax调用前缺少$。 That should do the trick. 这应该够了吧。

write $.ajax in inner ajax code    
$.ajax({
        type: "POST",
        url: "actionPages/billing.php",
        data: {
            custID: custID,
            credFName: credFName,
            credLName: credLName,
            credNum: credNum,
            credExpireMonth: credExpireMonth,
            credCVVNum: credCVVNum,
            credAddress: credAddress,
            credStreet: credStreet,
            credCity: credCity,
            credProvinState: credProvinState,
            credCountry: credCountry,
            credPostalZip: credPostalZip,
            credExpireYear: credExpireYear,
            dealID: dealID
        },
        dataType: 'json',
        success: function(response) {

            var credID = response;

            $.ajax({
                type: "POST",
                url: "actionPages/order.php",
                data: {
                    credID: credID,
                    custID: custID,
                    dealID: dealID
                },
                dataType: 'json',
                success: function(response) {

                },
                error: function (e) { console.log(e); }
            });
        },
        error: function (e) { console.log(e); }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM