执行两次jQuery的AJAX GET请求 [英] jquery ajax GET request executing twice

查看:689
本文介绍了执行两次jQuery的AJAX GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是在点击一个按钮,执行下面的Ajax请求:

I have the following ajax request that is executed at a click of a button:

<a href="javascript:test()"><img src="css/images/test.png"></a>

function test(){
    console.debug("*");

    $.ajax({
        type: "GET",
        dataType: "json",
        url: '/path/to/url',
        success: function(data){
            console.debug("**");
        }, 
        error: function(jqXHR, status, error){
            console.debug("*** " + status + " : " + error + " : " + jqXHR.status);
        },
        cache: false
    });
}

请求的响应时间为大约30秒返回。然而,该请求被接收到的并且由两倍可由apache的日志中可以看出的服务器执行。请求的时间戳分别是30秒间隔,但要求是相同的(例如,?_ ​​= 1363692320782)。点击响应函数被调用一次错误回调被调用一次(初始请求后,正好60秒),虽然Apache响应是200。

The request response takes approximately 30 seconds to return. However, the request is received and executed by the server twice as can be seen by the apache logs. The timestamp of the requests are 30 seconds apart but the request is identical (e.g ?_=1363692320782). The click response function is called once and the error callback is invoked once (exactly 60 seconds after initial request), although the apache response is a 200.

此问题已被复制了三星Galaxy S2,Android版本2.3.5在PhoneGap的应用程序。

This problem has been reproduced in a Samsung Galaxy S2, android version 2.3.5 in a phonegap application.

更新 - 从下面的评论加入Apache日志条目

1.2.3.4 - - [19/Mar/2013:14:07:59 +0000] "GET /pcapi/records/dropbox/08342hjg9gpqm7g/?_=1363702072225 HTTP/1.1" 200 11139 "-" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-gb; GT-I9100 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
1.2.3.4 - - [19/Mar/2013:14:08:29 +0000] "GET /pcapi/records/dropbox/08342hjg9gpqm7g/?_=1363702072225 HTTP/1.1" 200 11139 "-" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-gb; GT-I9100 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"

更新 - 亚行logcat

I/Web Console(16747): * at file:///android_asset/www/js/mobile.js:1769
I/Web Console(16747): *** error : : 0 at file:///android_asset/www/js/mobile.js:1779

更新 - TCP / IP监视器

通过TCP / IP监视器把请求显示正在发送的200响应为两个请求。

Putting the requests through a TCP/IP monitor shows both requests being sent with a 200 response for both.

推荐答案

我打这个确切的问题,在Android 2.3.5上运行我的应用程序。我只能得出这样的结论的WebView是一个重试超时后的请求。我找不到任何方式影响超时的持续时间。

I hit this exact problem with my app running on Android 2.3.5. I could only conclude that the webview was retrying the request after a timeout. I could find no way to affect the duration of the timeout.

在最后,我重写了code使得初始请求中剥离出来的异步处理的服务器上,并立即返回。然后,从页面上的SetTimer的,我会检查服务器进程的状态(再次,立即返回)。当状态是完整的,该网页将沿移动到下一个步骤。

In the end, I rewrote the code such that the initial request spun off an asynch process on the server and returned immediately. Then, from a setTimer on the page, I would check the status of the server process (again, returning immediately). When the status was "complete", the page would move along to the next step.

我希望帮助。我当然明白你的无奈与此有关。我花了几天自己与它战斗。

I hope that helps. I certainly understand your frustration with this. I spent a couple of days myself fighting with it.

编辑:这可能是发送我的异步解决的方向的文章。相信这里所述的问题是一个相同的:

This may have been the article that sent me in the direction of an asynchronous solution. I believe the problem stated here is one and the same:

<一个href="http://stackoverflow.com/questions/9526509/xmlhtt$p$pquest-double-posting-issue-in-android">XmlHtt$p$pquest在Android的双张贴问题

这篇关于执行两次jQuery的AJAX GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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