简体   繁体   中英

abort a window.location.hash

I have a url say www.abc.com which display all data of a table

I have search box in the page which calls a function search() on keyup

//search function
function search(){
    window.location.hash = "?query="+$("#search).val(); /* goes to the page and get data*/
}

When I type any key say a, it will send a the request www.abc.com?query=a and get all data starting with a When I type any key say aa, it will send the request www.abc.com?query=aa and get all data starting with aa

I want to know a way to abort the request www.abc.com?query=a when www.abc.com?query=aa is send because it takes a lot of time

Whatever "goes to the page and get data" is, it should return a handle. For instance, if you're using the Vanilla JS XMLHttpRequest , then you can return that object.

Then, before loading a new search, call its abort method to cancel the old one.

Note that this may not actually cancel it on the server side, so be careful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM