Select to view content in your preferred language

Cancelling an already running query

1239
4
02-22-2012 12:47 AM
Salomon_VágadalJoensen
Deactivated User
I have an application that queries the mapserver as you type in a text box.

Is there a way to cancel a query? The situation is that a user might type in the text box; the first letter sends a query for that one letter, but then the user types a second letter, such that there are 2 queries running simultaneously, and the 2nd query comes back before the 1st query. E.g. a user types "r", which takes a while for the server to return the results for, but before that happens the user has subsequently typed "re", a shorter query which comes back before the first one.

I want to cancel any running query as soon as a letter is typed, maybe have an IF condition for checking if a query is already running, or some other similar solution.
0 Kudos
4 Replies
Salomon_VágadalJoensen
Deactivated User
I've tried setting up and use cancel method for a queryTask. Every time I cancel a query operation, though, I get an dojo.io.script error.

I think the query is genuinely terminated, I'm just worried about that error callback I'm getting.
0 Kudos
JeffPace
MVP Alum
I've tried setting up and use cancel method for a queryTask. Every time I cancel a query operation, though, I get an dojo.io.script error.

I think the query is genuinely terminated, I'm just worried about that error callback I'm getting.


I dont think the querytask has a cancel method, at least not according to the API documentation.  Once the query is submitted to the server I don't think there is much you can do to stop it.
0 Kudos
Salomon_VágadalJoensen
Deactivated User
I got the inspiration for query cancellation from here, the 2nd last post code snippet:

http://forums.arcgis.com/threads/36248-Is-it-possible-to-destroy-a-QueryTask-while-it-s-executing

EDIT: Also, I've looked at dojo deferred list, if that can be used, but am unsure on how to.
0 Kudos
markburrell
Deactivated User
We had a similar thing while searching against a database used for an interactive quick search much like google. The solution was to set up a timer to wait for a number of seconds before auto running the query. If the user typed another letter before the timeout value then the timer would reset and start again.
Something like this.

check for keyup event inside text entry box first.

        dojo.connect(this.qSearch, "onkeyup", this, dojo.hitch(this, "_checkInput"));

this.qSearch is a ref to the Dom node of the input box.

The timer function runs before doing the query in the _filterText function.

        _checkInput: function () {
        clearTimeout(this.timer);
        this.timer = setTimeout(dojo.hitch(this, "_filterText"), 2000);
        },


this hitches to the function you want to run once the timeout reaches 2 seconds. If a key is pressed before the 2 seconds has expired the timer begins again.
0 Kudos