[英]objective-C get HTML value after ajax call in UIWebView
I want to get div
value that gets created after an HTML button click
in UIWebView
. 我想获取在UIWebView
HTML button click
后创建的div
值。
But the issue is that the webpage gets loaded once and after the HTML button ajax call
, it doesn't get loaded again in the UIWebView
, so how do I access the div
value that gets generated after the ajax
call? 但是问题在于,在HTML button ajax call
之后一次加载了网页,而在UIWebView
中没有再次加载该网页,那么如何访问在ajax
调用之后生成的div
值?
Following is the html code: 以下是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>
Following is the objective-c code: 以下是objective-c代码:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if([webView.request.URL.absoluteString isEqualToString:@"http://myurl.com/"])
{
//some code that executes only once
}
}
How do I solve this? 我该如何解决?
You can execute this javascript code when webview didFinishLoading delegate method called. 您可以在调用webview didFinishLoading委托方法时执行此javascript代码。 Like this [webView stringByEvaluatingJavaScriptFromString:@""]
Then you will get ajax based request callbacks 像这样[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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.