2015-09-08 129 views
2
How can i stop an request which is already being processing in backend ? 

I am using EXT Js Framework,There are two button , 
1.Search button 
    This button queries the back end and fetches the required JSON output 
    Usually it takes a long time to process from the backend . 
    In my window i will be seeing the processing dialogue box. 
2.Stop Button 
    The new requirement what i need here is to stop/abort/cancel 
    the existing search request . 
    How can cancel the existing request when stop button is clicked . 
    Do i need to do some coding in Backend or Front End ? 
    Any tricks , please help. 

下面是代碼片段如何停止已在後端處理的請求?

// 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 
    } 
}); 
+0

雖然@air答案被接受有人可以幫我一個辦法,停止後臺運行的線程,這樣我可以終止後臺查詢? – Mahi29

回答

0

嘗試使用XMLHTTPRequest.abort() 在你的情況下,嘗試

function stopSearch(){ 
    connObj.abort(); 
} 
0

您可以中止一個XMLHttpRequest,但不保證該服務器將停止處理該請求。

例如在PHP中,您可以這樣做:ignore_user_abort(true)。它主要取決於您的服務器技術。

相關問題