简体   繁体   English

Objective-C在UIWebView中进行Ajax调用后获取HTML值

[英]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="{ &quot;container&quot;: &quot;betInfoTabReceipts&quot;, &quot;onComplete&quot;: &quot;ajaxOnCompleteTabs&quot;, &quot;onLoading&quot;: &quot;ajaxOnLoadTabs&quot;}" action="/some.something" onclick="$P('place_bet', {&quot;action&quot;: this.getAttribute('action'), &quot;params&quot;: this.getAttribute('params'), &quot;confirm&quot;: &quot;true&quot;}); 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.

相关问题 如何在Objective-C中获取HTML表的值? - How to get a value of an HTML table in Objective-C? UIWebView 中的 Javascript 回调到 C/Objective-C - Javascript in UIWebView callback to C/Objective-C 在UIWebView的Objective-c中注入JQuery函数 - Injecting JQuery function in Objective-c in UIWebView 如何在UIWebView中从Javascript调用Objective-C方法? - How do I call an Objective-C method from Javascript in UIWebView? Objective-c [For循环]在UIWebview中加载HTML并从JavaScript函数检索数据 - Objective-c [For loop] load HTML in UIWebview and retrieve data from JavaScript function Objective-C的 - 获得一个UIWebView动态size.height的文档内容的潜在修改后 - Objective-C – Getting a UIWebView dynamic size.height after a potential modification of document content 是否可以调用向JavaScript返回值的Objective-C函数? - Is it possible to call an Objective-C function that returns a value to javascript? 如何从UIWebView传递数据到Objective-C IOS中的本机应用程序 - How to get data from UIWebView pass to Native app in Objective-c IOS 从Objective-C将大数据传递到UIWebView JavaScript - Passing large data to UIWebView javascript from Objective-C 在没有可见的uiwebview的情况下调用javascript Objective-C - calling javascript objective-c without visible uiwebview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM