Question

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!

Was it helpful?

Solution 2

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.

OTHER TIPS

If you're using an XMLHttpRequest object, you can call .abort().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top