cancel a query task in javascript

1989
4
10-25-2012 12:32 AM
kundkwong
New Contributor
How to cancel the querying task in the middle of query process and stop all query process. anyone help pls
0 Kudos
4 Replies
__Rich_
Occasional Contributor III
The execute* methods all return dojo/Deferred so you might be able to call cancel() on the deferred object...
0 Kudos
kundkwong
New Contributor
The execute* methods all return dojo/Deferred so you might be able to call cancel() on the deferred object...


thanks for ur replying, but what i need is cancel all the process

deferred object has the cancel() method, but it's not related to the query callback function

so, when query task completed, the callback function will run and it won't be able to stop by cancel(), isn't it?
0 Kudos
__Rich_
Occasional Contributor III
deferred object has the cancel() method, but it's not related to the query callback function

Have you read the dojo/Deferred documentation?

The QueryTask.execute() method wraps an esri.request which in turn wraps some Dojo AJAX (XHR and IO) stuff, the Dojo components support cancel() using the approach I described.  Whether or not the wrappers above those components permit cancel() to work as it should I have no idea e.g. IIRC you're supposed to pass a "canceller" to the deferred constructor and I think I may have seen a canceller being passed somewhere in the depths of the Esri code...(in Dojo 1.8 there's a default canceller)

Perhaps you should try it?  (I recommend you do some reading first though)

What's your aim with all of this?  (what problem are you specifically trying to solve?)
0 Kudos
PeterLi1
New Contributor III

Encounter the same issue. If the query takes too long, we really want to cancel it. How to do it?

0 Kudos