简体   繁体   English

jQuery Ajax调用未处理.done

[英]jQuery Ajax call not processing .done

I have been beating my head against this desk, and I am not sure why javascript/jQuery (1.71) is not completing it's tasks before doing something else. 我一直在桌子前跳动我的头,我不确定为什么javascript / jQuery(1.71)在做其他事情之前没有完成任务。

I am calling a function that is strictly a jQuery Ajax call. 我正在调用的函数严格是jQuery Ajax调用。 The function performs the Ajax portion, but the .done is not being processed before it leaves the function and returns to the original calling function. 该函数执行Ajax部分,但是.done在离开该函数并返回到原始调用函数之前未得到处理。

If you look through the code, I stripped out non-essential code, but left the call. 如果您仔细看一下代码,我会剔除非必要的代码,但还是打了电话。 So I call the processAjax function. 所以我调用了processAjax函数。 As I trace through it, the function is called, the Ajax process is performed, and then it returns to the dups function and the alert ('stopping here') is triggered before the done section is processed. 当我进行跟踪时,将调用该函数,执行Ajax进程,然后返回到dups函数,并在处理完部分之前​​触发警报(“在此处停止”)。

What's going on?!? 这是怎么回事?!?

Here is some code: 这是一些代码:

function dups(){
    $('#dupChecker').val(2);
    if ($('#spDegree').length){
    // do logic here

    }

    else if ($('#meetingID').length){
    // do logic here            
    }

    else {
    // do logic here            
    }

    processAjax(user, actDate, meetID, degree, act);

    alert('stopping here');

    return 0;

};

function processAjax(a,b,c,d,e){

    $.ajax({
        url: "deSubmit_testDups.cfm",
        cache:false,
        method: "POST",
        data: {id:a, aDate:b, meet:c, degree:d, act:e},
        dataType: "html"
    })          

    .done(function( html ) {
        myResult = parseInt($.trim( html ));
        alert ('myresult= '+ myResult);
        if (myResult == 0){
            $('#submitBTN').prop("disabled",false);
            $('#errorMsg').css("visibility","hidden");
            $('#dupChecker').val(1);
        }
        else {
            $('#submitBTN').prop("disabled",true);
            $('#errorMsg').css("visibility","visible");
            $('#dupChecker').val(0);
        }
    })

    .fail(function( jqXHR, textStatus ) {
    alert( "Request failed: " + textStatus );
    });

};
function dups(){
    $('#dupChecker').val(2);
    if ($('#spDegree').length){
    // do logic here

    }

    else if ($('#meetingID').length){
    // do logic here            
    }

    else {
    // do logic here            
    }

    processAjax(user, actDate, meetID, degree, act, function(resp){
         alert('stopping here');
    });



    return 0;

};

function processAjax(a,b,c,d,e, callback){

    $.ajax({
        url: "deSubmit_testDups.cfm",
        cache:false,
        method: "POST",
        data: {id:a, aDate:b, meet:c, degree:d, act:e},
        dataType: "html"
    })          

    .done(function( html ) {
        myResult = parseInt($.trim( html ));
        alert ('myresult= '+ myResult);
        if (myResult == 0){
            $('#submitBTN').prop("disabled",false);
            $('#errorMsg').css("visibility","hidden");
            $('#dupChecker').val(1);
        }
        else {
            $('#submitBTN').prop("disabled",true);
            $('#errorMsg').css("visibility","visible");
            $('#dupChecker').val(0);
        }
        callback();
    })

    .fail(function( jqXHR, textStatus ) {
        alert( "Request failed: " + textStatus );
        callback();
    });

};

Hope this helps you. 希望这对您有所帮助。 You can use a callback to make it synchronous. 您可以使用回调使其同步。 You can also pass the ajax response to the callback. 您还可以将ajax响应传递给回调。

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

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