我想获取div
在UIWebView
HTML button click
后创建的值。
但问题是网页加载一次,HTML button ajax call
后,它不会在UIWebView
中再次加载,那么我如何访问ajax
调用后生成的div
值呢?
以下是 html 代码:
<a class="btn_class" params="{ "container": "betInfoTabReceipts", "onComplete": "ajaxOnCompleteTabs", "onLoading": "ajaxOnLoadTabs"}" action="/some.something" onclick="$P('place_bet', {"action": this.getAttribute('action'), "params": this.getAttribute('params'), "confirm": "true"}); return false;" id="btn_id" href="#"></a>
以下是 objective-c 代码:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if([webView.request.URL.absoluteString isEqualToString:@"http://myurl.com/"])
{
//some code that executes only once
}
}
我该如何解决这个问题?
您可以在调用 webview didFinishLoading delegate 方法时执行此 JavaScript 代码。像这样[webView stringByEvaluatingJavaScriptFromString:@""]
然后你会得到基于 ajax 的请求回调
var s_ajaxListener = new Object();
s_ajaxListener.tempOpen = XMLHttpRequest.prototype.open;
s_ajaxListener.tempSend = XMLHttpRequest.prototype.send;
s_ajaxListener.callback = function () {
window.location='mpajaxhandler://' + this.url;
};
XMLHttpRequest.prototype.open = function(a,b) {
if (!a) var a='';
if (!b) var b='';
s_ajaxListener.tempOpen.apply(this, arguments);
s_ajaxListener.method = a;
s_ajaxListener.url = b;
if (a.toLowerCase() == 'get') {
s_ajaxListener.data = b.split('?');
s_ajaxListener.data = s_ajaxListener.data[1];
}
}
XMLHttpRequest.prototype.send = function(a,b) {
if (!a) var a='';
if (!b) var b='';
s_ajaxListener.tempSend.apply(this, arguments);
if(s_ajaxListener.method.toLowerCase() == 'post')s_ajaxListener.data = a;
s_ajaxListener.callback();
}