Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何停止已在后端处理的请求?_Javascript_Ajax_Extjs_Xmlhttprequest - Fatal编程技术网

Javascript 如何停止已在后端处理的请求?

Javascript 如何停止已在后端处理的请求?,javascript,ajax,extjs,xmlhttprequest,Javascript,Ajax,Extjs,Xmlhttprequest,您可以中止XMLHTTPRequest,但不能保证服务器会停止处理该请求 例如,在PHP中,您可以执行:ignore\u user\u abort(true)。这主要取决于您的服务器技术。尝试使用XMLHTTPRequest.abort() 在你的情况下,试试看 // Search panel with two buttons var searchPanel = new Ext.FormPanel({ frame:true, title: 'Search

您可以中止XMLHTTPRequest,但不能保证服务器会停止处理该请求


例如,在PHP中,您可以执行:
ignore\u user\u abort(true)
。这主要取决于您的服务器技术。

尝试使用
XMLHTTPRequest.abort()
在你的情况下,试试看

// Search panel with two buttons

    var searchPanel = new Ext.FormPanel({
        frame:true,
        title: 'Search Criteria',
        collapsible:true,
        defaultType: 'textfield',
        region:'west',
        autoScroll:true,

        // has few text box for input search 

        ],
        buttons: [{
                id: 'search-button',
                text:'Search',
                handler:applySearch
            },{
                id:'stop-button',
                text:'Stop',
                handler:stopSearch
            }
        ]
    });

    function applySearch(){
        applySearchFunction('search');
    }


    function applySearchFunction() {
        //calls the store with required fields

    }

    function stopSearch(){
        //What is the hack i need to place here in order to abhort/cancel the request which is already in processing state.
    }



var reader = new Ext.data.JsonReader({
    id:'id'
    ,totalProperty:'total'
    ,root:'rows'
    ,fields:[
        // required fields
    ]
});

function handleServerTimeOutError(conn, response, options) {
        if(response.status == 504){
            Ext.Msg.alert(
                'Timed out',
                'The search operation timed out, please try again'
            );
        }
}
// Back end call is happening here .. 
var connObj = new Ext.data.Connection({
    timeout : toMS(60),
    url : 'file contains json logic',
    method : 'POST',
    listeners: {
        requestexception: handleServerTimeOutError
    }
});

var store = new Ext.data.GroupingStore({
    reader: reader,
    //use proxy so we can set timeout
    proxy : new Ext.data.HttpProxy(connObj),
    //autoLoad: 'true',
    remoteSort: true,
    listeners: {
        beforeload: startIdleTimer
    }
});

虽然@air的答案被接受,但有人能帮我停止后台线程的运行,这样我就可以在后台终止查询了吗?
// Search panel with two buttons

    var searchPanel = new Ext.FormPanel({
        frame:true,
        title: 'Search Criteria',
        collapsible:true,
        defaultType: 'textfield',
        region:'west',
        autoScroll:true,

        // has few text box for input search 

        ],
        buttons: [{
                id: 'search-button',
                text:'Search',
                handler:applySearch
            },{
                id:'stop-button',
                text:'Stop',
                handler:stopSearch
            }
        ]
    });

    function applySearch(){
        applySearchFunction('search');
    }


    function applySearchFunction() {
        //calls the store with required fields

    }

    function stopSearch(){
        //What is the hack i need to place here in order to abhort/cancel the request which is already in processing state.
    }



var reader = new Ext.data.JsonReader({
    id:'id'
    ,totalProperty:'total'
    ,root:'rows'
    ,fields:[
        // required fields
    ]
});

function handleServerTimeOutError(conn, response, options) {
        if(response.status == 504){
            Ext.Msg.alert(
                'Timed out',
                'The search operation timed out, please try again'
            );
        }
}
// Back end call is happening here .. 
var connObj = new Ext.data.Connection({
    timeout : toMS(60),
    url : 'file contains json logic',
    method : 'POST',
    listeners: {
        requestexception: handleServerTimeOutError
    }
});

var store = new Ext.data.GroupingStore({
    reader: reader,
    //use proxy so we can set timeout
    proxy : new Ext.data.HttpProxy(connObj),
    //autoLoad: 'true',
    remoteSort: true,
    listeners: {
        beforeload: startIdleTimer
    }
});
function stopSearch(){
     connObj.abort();
}