How to handle incoming ajax requests after window is destroyed?

I am creating a window that contains grids that send ajax requests. Now I will close the window again before the grids are fully created and the ajax requests are returned.

I have two problems:

  • My components inside the window are still alive after the window is destroyed

The Chrome console lists them. Although my window has autoDestroy: true

, the grid and storage still exist after the window is closed. An event occurs on close destroy

. The documents say all the components under the window must be destroyed.

  • Then my callbacks finally return and execute, but the window is destroyed

The problem is the callbacks are trying to reconfigure the grid that no longer has the storage attached.

Error: Uncaught TypeError: Cannot call method 'getCount' of null Table.js:500

(/lib/extjs/src/view/Table.js

How can I stop callbacks from processing if my window has been destroyed?

+2


source to share


1 answer


Registering events with mon so that they are removed when the listener is destroyed. Alternatively, you can:

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

Edit

There are a few more things you can do



  • check if the destroy () methods of the grid are called
  • cancel all requests by calling Ext.Ajax.abortAll () (before the window is closed)
  • abort only a specific request by calling Ext.Ajax.abort (request) (before closing the window)

I recommend using option 2. because it should be the safest.

Edit 2

To see all execution requests, you need to look at the personal property requests

Ext.data.Connection

from which it is Ext.Ajax

distributed. requests

has an object of type and will contain a property (request id) for each request currently in progress.

+5


source







All Articles