简体   繁体   中英

jQuery ajax done callback behaves strange in firefox

I have an issue with jQuery 1.7.1 and the ajax function in firefox. I am doing an ajax call that requests json from a CMIS server. In chrome everything works fine. Let me give you an example:

function ajaxCall(url, requestType, isAsync, parameters, doneCb, failCb) {
    $.ajax(url, {
        type: requestType,
        async: isAsync,
        data: parameters
    }).done(
        alert("test"),
        // the following function gets not executed in firefox with async: true
        function (result) {
            doneCb(result);
        }).fail(function (cause) {
            failCb(cause);
        });
}

The strange thing in firefox is that if I am using async: false everything works like a charm. In case I use async: true the done callback is also executed and the alert pop up with the message "test" appears. BUT the function after the alert doesn't get executed. I googled a lot and couldn't find a solution for this problem.

You are my last hope ;)

Thanks and Best Regards, Simon

I also tried the old fashioned way but the result is still the same - the success function doesn't get called in firefox if async is true.

 $.ajax(url, {
        type: requestType,
        async: isAsync,            
        data: parameters,
        success: function(result){
            doneCb(result);
        },
        error: function(cause){
            failCb(cause);
        }
    });

That code is taking the alert and assigning what it returns to the first argument of done. It is executing when the function is being initialized, not when the done() method is actually called.

It should look like

.done( 
    function() { alert("test") },
    function() { ... }
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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