How to handle incoming ajax requests after destroying window?

拥有回忆 提交于 2020-01-15 03:17:13

问题


I create a window containing grids that send off ajax requests. Now, I immediatley close the window again before the grids are fully created and the ajax requests return.

I have two problems:

  • My components within a window are still "alive" after a window is destroyed

Chrome console lists them. Although my window has the autoDestroy: true the gridpanel and store are still existing after the window is closed. When closed, the destroy event is fired. Docs say, all components under the window should be destroyed.

  • Then my callbacks finally return and get executed but the window is destroyed

The problem is, that the callbacks try to reconfigure a grid that has no more store attached.

Error: Uncaught TypeError: Cannot call method 'getCount' of null Table.js:500 (/lib/extjs/src/view/Table.js

How can I stop the callbacks from processing if my window is destroyed?


回答1:


Registering the events with mon so that they get removed when the listening object get destroyed. Alternatively you may:

  • remove them manually within the destroy() method
  • check within the callback for methods or properties that may not exist to skip them

Edit

There are some more things that you can do

  1. check if the destroy() methods of the grids get called
  2. abort all request by calling Ext.Ajax.abortAll() (before the window close)
  3. abort just specific requestst by calling Ext.Ajax.abort(request) (before the window close)

I recommend to use option 2. because it should be the safest.

Edit 2

To take a look at all running request you need to look at the private requests property of Ext.data.Connection from which Ext.Ajax extend. requests is of type object and will contain a property (the request Id) for each request that is currently running.



来源:https://stackoverflow.com/questions/17591127/how-to-handle-incoming-ajax-requests-after-destroying-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!