Jquery AJAX 对 pylon 的调用在相同请求上间歇性失败

发布于 2024-12-02 03:23:59 字数 1632 浏览 0 评论 0原文

我正在创建一个像这样的ajax调用:

  var form = $("#form");
  $.ajax({url: "/url/create_web_registration?invite_token=abc",
          data: form.serialize(),
          type: "POST",
          dataType: "json",
          success: $.web_registration.index.registerSubmitSuccess,
          error: $.web_registration.index.registerSubmitError,
  });

但是,当我使用相同的参数重复请求时,我有时会得到成功回调,有时会得到错误回调。当调用错误回调时,失败时 jqXHR.status 始终为 0,但 statusText、responseText、textStatus 或 errorThrown 中没有任何描述性内容。

我对 HTTP 请求进行了 tcpdump,请求看起来像:

POST /shopkick/v1/user/create_web_registration?invite_token=abc HTTP/1.1
Host: [redacted]:5000
Connection: keep-alive
Referer: http://[redacted]:5000/wr2/abc?invite_token=&zip_code=94123&phone_number=%2B16785556982&facebook-form=
Content-Length: 169
Origin: http://[redacted]:5000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

invite_token=&zip_code=94123&phone_number=%2B16785552982

响应看起来像:

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.6.1
Date: Wed, 31 Aug 2011 05:34:10 GMT
Pragma: no-cache
Cache-Control: no-cache
Content-type: text/plain
Content-Length: 74

{"error_message": "Facebook account already registered", "success": false}

我不知道为什么它有时会成功,有时会失败。

I am creating an ajax call like so:

  var form = $("#form");
  $.ajax({url: "/url/create_web_registration?invite_token=abc",
          data: form.serialize(),
          type: "POST",
          dataType: "json",
          success: $.web_registration.index.registerSubmitSuccess,
          error: $.web_registration.index.registerSubmitError,
  });

However when I repeat the request with identical parameters, I sometimes get the success callback and sometimes get the error callback. When the error callback is called, the jqXHR.status is always 0 on a failure, but there is nothing descriptive in statusText, responseText, textStatus or errorThrown.

I did a tcpdump on the HTTP requests and the request looks like:

POST /shopkick/v1/user/create_web_registration?invite_token=abc HTTP/1.1
Host: [redacted]:5000
Connection: keep-alive
Referer: http://[redacted]:5000/wr2/abc?invite_token=&zip_code=94123&phone_number=%2B16785556982&facebook-form=
Content-Length: 169
Origin: http://[redacted]:5000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

invite_token=&zip_code=94123&phone_number=%2B16785552982

The response looks like:

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.6.1
Date: Wed, 31 Aug 2011 05:34:10 GMT
Pragma: no-cache
Cache-Control: no-cache
Content-type: text/plain
Content-Length: 74

{"error_message": "Facebook account already registered", "success": false}

I am at a loss to why it is sometimes succeeding and sometimes failing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2024-12-09 03:23:59

问题是我正在使用ajax 提交表单。当我单击“提交”按钮时,它会正常工作,但是当我在文本输入字段中按回车键时,它会遇到错误。显然,在输入字段中按 Enter 键会导致表单提交两次。解决方法是设置 onsubmit="return false;"用于防止重复提交的表单。

The problem was I was using ajax to submit a form. When I clicked the submit button it would work fine, but when I hit enter in a text input field it would encounter the errors. Apparently hitting enter in a input field was causing the form to submit twice. The fix was to set onsubmit="return false;" for the form to prevent double submission.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文