安卓:从截取的WebView AJAX调用 [英] Android: Intercept AJAX call from WebView
问题描述
我希望有一个 HTML / JavaScript的
的应用,在的WebView
,使 AJAX运行
是由的Java
code处理的呼叫。
理想的做法是只截取呼叫(简单,只需使用 shouldOverrideUrlLoading()
)和回归的一些数据。
但是,我没有找到一种方法,回归到的WebView
,不是调用 JavaScript的其他
响应使用功能使用loadURL()
。
这不会为我工作,因为 HTML / JavaScript的
应用程序是一个简易的应用程序,我无法控制。至于HTML / JavaScript的应用程序的关注,它只是一个 AJAX
通话和接收的一些数据了。
I want a HTML/javascript
application, running in a WebView
to make AJAX
calls that are handled by the Java
code.
Ideal would be to just intercept the call (easy, just use shouldOverrideUrlLoading()
) and 'return' some data.
However, I don't find a way to 'return' a response to the WebView
, other than calling a javascript
function using loadUrl()
.
This will not work for me, as the HTML/javascript
app is a drop-in application which I don't control. As far as the HTML/javascript app concerns, it just does an AJAX
call and receives some data back.
在这个有什么想法?
推荐答案
在最后,我用的问题描述的方法呢;
In the end I used the method described in the question anyway;
我截取喜欢一些具体要求:富://酒吧/得/ 1回调= foobar的
然后分析了网址
,并要求与实际数据的一个JavaScript回调函数。
回调函数是在 URL的查询部分定义
,所以在上面的例子中,这将是: foobar的();
I intercepted some specific requests like: foo://bar/get/1?callback=foobar
then parsed the URL
and called a javascript callback function with the actual data.
The callback function was defined in the query-part of the URL
, so in the above example that would be: foobar();
调用该函数很简单,只需使用: yourWebView.loadUrl(JavaScript的:foobar的('somedata'));
Calling that function was easy, just use: yourWebView.loadUrl("javascript:foobar('somedata')");
这篇关于安卓:从截取的WebView AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!