阿贾克斯同步超时的WebView [英] Synchronous Ajax Timeout in webview

查看:439
本文介绍了阿贾克斯同步超时的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然做一个同步Ajax请求(GET)从JavaScript从web视图中的Andr​​iod跨域的网站,请求失败。 在code是如下图所示,

While doing a synchronous ajax request (GET) from javascript to a cross domain website from webview in Andriod, the request fails. The code is like below,

  var jqxhr = $.ajax({
    url: url,
    cache: false,
    dataType: 'json',
    type: 'GET',
    async: false
  })
  .done(function ( data ) { fnSuccess(JSON.stringify(data)); });

  jqxhr.fail(function(jqXHR, textStatus, errorThrown) {
    alert("Failed with:"+textStatus+"--"+errorThrown+"--"+jqXHR.status+"--"+jqXHR.responseText);
  });

网站应该返回我数据JSON格式和平均响应时间约为90秒。 该网站的网址是什么样子, https://abc.com/abc ?/ 123 = 1和b = 2和C = 3

The website is supposed to return me data in JSON format and the average response time is around 90 seconds. The website url is like, https://abc.com/abc/123?a=1&b=2&c=3

下面登录时,Ajax请求开始(亚行logcat)显示, E / WebUrlLoaderClient(924):同步请求超时10秒后的第0试试,网址: https://abc.com/abc/123?a=1&b=2&c=3 E / WebUrlLoaderClient(924):同步请求超时10秒的第1试试,网址后:... E / WebUrlLoaderClient(924):同步请求超时10秒后为二路试试,网址:

Below log is shown when the Ajax request starts (adb logcat), E/WebUrlLoaderClient( 924): Synchronous request timed out after 10 seconds for the 0th try, URL: https://abc.com/abc/123?a=1&b=2&c=3 E/WebUrlLoaderClient( 924): Synchronous request timed out after 10 seconds for the 1th try, URL: ... E/WebUrlLoaderClient( 924): Synchronous request timed out after 10 seconds for the 2th try, URL: ...

在记录3号线,Ajax请求改变就绪状态为4,响应状态为0,而不是200和响应文本也为空。这意味着它是30秒后超时。

After the 3rd line is logged, the ajax request changes the ready state to 4 and the response status to 0 instead of 200 and the response text is also null. This means it is timing out after 30 seconds (3 retries of 10 seconds each).

我经历了WebUrlLoaderClient.cpp从Android的开源和发现,超时和重试次数是固定的,以分别为10和3。

I went through the WebUrlLoaderClient.cpp from Android open source and found that the timeout and the number of retries are fixed to 10 and 3 respectively.

这同样的要求是工作的罚款在异步模式下。

This same request is working fine in asynchronous mode.

请让我知道我是否做这个code什么问题或有任何其他方式做一个同步Ajax调用其中的响应时间超过30秒。

Please let me know whether I am doing anything wrong in this code or is there any other way to do a synchronous ajax call where the response time is more than 30 seconds.

推荐答案

我怕你不能够设置自定义超时同步Ajax调用...你必须去异步的,把你下入.done和。失败Ajax调用。

I am afraid you are not able to set a custom timeout for synchronous ajax call... you have to go asynchronous and put your next into .done and .fail ajax calls.

在这里看到:登录工作为iPhone而不是Android的

这篇关于阿贾克斯同步超时的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆