在 iPhone 中的 UIWebView 中停止 Ajax 请求
我有一个 UIWebView 控件加载一个在 HTML 上有 AJAX 的 URL。我关心的是停止页面上的 AJAX 请求。我可以通过使用委托方法来停止所有进一步的导航,如下所示:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest: (NSURLRequest*)req navigationType:(UIWebViewNavigationType)navigationType {
或者我可以使用简单的方法 [webView stopLoading]
,但这些方法都无法停止在浏览器上运行的内部 AJAX 请求。
请建议是否有任何方法可以阻止 AJAX
I have a UIWebView control loading a URL that have AJAX on HTML. My concern is to stop AJAX request on the page. I can stop all further navigation by using delegate method as:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest: (NSURLRequest*)req navigationType:(UIWebViewNavigationType)navigationType {
Or I can use the simple method [webView stopLoading]
, but non of these able to stop internal AJAX request running on browser.
Please suggest if is there any way where we can stop AJAX
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ajax URL 不会传递给 shouldStartLoadWithRequest,仅加载页面和 iframe。要捕获任何其他类型的网络流量,您可以使用 NSURLCache,它基本上是 UIWebView 和网络之间的缓存层。它还可以根据您定义的某些规则捕获请求,并为其返回错误或空响应,就好像该错误位于缓存中一样。
以下是替换某些 url 内容的示例:
http://cocoawithlove.com/2010/09/substituting-local -data-for-remote.html
Ajax URLs are not passed to shouldStartLoadWithRequest, only page and iframe loads. To capture any other sort of network traffic you can use NSURLCache which is basically a cache layer between UIWebView and network. It can also capture requests based on some rules you defined and return an error or empty response for it as if that error was in the cache.
Here is a sample to replace some url content:
http://cocoawithlove.com/2010/09/substituting-local-data-for-remote.html