jquery ajax call not asynchronous

泄露秘密 提交于 2019-12-01 08:20:35

I have discovered the cause of the javascript call hanging.

To prevent a race condition from occurring with user session data, PHP locks the data until one of two conditions occur.

  1. The previously called PHP script calls session_write_close().

  2. The previously called PHP script completes processing and implicitly calls session_write_close().

Following the logic that a call to the server that does not call session_start() should allow true asynchronous calls, I created a dummy PHP page that just spits out a simple string and called to that page every second while the 10 second script ran. It ran perfectly.

The solution came from reading this discussion on the symfony forums.

What about something like

I dropped the try catch's and made your setTimeout's to look like check_id = setTimeout(progressCheck, 1000);

function beginLogin(){
    var login_url = "http://example.com/home/loginScript";
    return $.ajax({
        url: login_url,
        success: function(data){
            $("#result_div").append('<pre>' + data + '</pre><hr/>');
            alert("finished");
        },
        error: function(a, b, c){
            console.log(a)
            console.log(b)
            console.log(c)
        }
    });
}

function progressCheck(){
    var check_url = "http://example.com/home/checkLoginProgress";
    var ajax = $.ajax({
        url: check_url,
        success: function(data){
            $("#progress_div").append('<pre>' + data + '</pre><hr/>');
        },
        error: function(a, b, c){
            console.log(a)
            console.log(b)
            console.log(c)
        }
    });

    check_id = setTimeout(progressCheck, 1000);
    return ajax;
}

// set progress checking function to call every second
var check_id = setTimeout(progressCheck, 1000);

function clearCheck(){
    try {
        clearTimeout(check_id);
    } catch (e) {
        alert("There was an error clearing the check: " + e);
        return false;
    }
    return true;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!