Javascript 如何停止已在后端处理的请求?
您可以中止XMLHTTPRequest,但不能保证服务器会停止处理该请求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
例如,在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();
}