简体   繁体   中英

How to cancel the http request in Javascript?

I'm building a hybrid iOS App. Some UIs are drawn by HTML5 in a UIWebView. The HTML5, Javascript, and CSS are all deployed on the server and the app loads the HTML5 page by sending a URL request.

If the app needs to load some date from server, the HTTP request is sent by Javascript in and HTML5 page instead of being sent by a native Objective C code. My question is: How can I cancel the HTTP request that has been sent by Javascript, for instance, if the view controller calls popToViewController, we want to cancel the unfinished http request?

If the HTTP request sent by native code, we can cancel it by calling the "cancel" method of NSURLConnection, but I have no idea how to cancel the HTTP request that is sent by the Javascript code.

Thanks in advance!

如果使用的是XMLHttpRequest对象,则可以调用.abort()

if you are using jquery you need to use request.abort(); but, its only works inside the js on the same script that runing. and remember that overtime you are sending a request via your app - you you are loading a new web page and a new js, so if you trying to do it from the app - i do not think its possible.

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