在Firefox的jQuery阿贾克斯失败 [英] jquery ajax fails in firefox

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

问题描述

我有多个Ajax和我处理上完成和失败。

i have multiple ajax and i handle on done and on fail.

$.when(

   $.ajax({
        url: "/ajax",
        type: "POST",
        data: {
             _xsrf: xsrf_token,
             'action': "/document/x",
             'values': JSON.stringify(values)
             }
      }).done(function() {
           console.log("done!");
           window.location.reload();
      }).fail(function(jqXHR, textStatus) {
           console.log(jqXHR);
           $('#error').text(textStatus);
  })
).then(function() {

 // All have been resolved (or rejected)

 });

在Chrome和IE浏览器时,Ajax是succesfull它做完结束,并显示一些信息,即电话是sucessfull和页面重新加载。在FF如果调用succesfull它会先在失败和它去中完成..任何想法?

In chrome and IE when the ajax is succesfull it ends in done, and shows some message that the call was sucessfull and the page is reloaded. In FF if the call is succesfull it goes first in fail and the it goes in done .. any idea?

编辑:

此行​​为是只在特定的情况下:我想删除,并添加相同的用户数据库在$。当2 asynchron呼叫:从用户侧是可能的,但asynchron呼叫处理的不同在不同的浏览器。

This behaviour is only in a specific case: I am trying to remove and also add the same user in the database in two asynchron calls in the $.when: which from user side is possible, but the asynchron calls are handled different in the different browsers.

推荐答案

我觉得你滥用的jQuery 。当(),因为该方法是递延对象,它实现了无极接口,然后在 jqXHR 对象通过 jQuery.ajax()返回实施无极接口 ,给人一种 无极 (更多信息请参见 Deferred对象

I think you are misusing the jQuery.when(), because that method is part of the Deferred object, which implements the Promise interface, and the jqXHR object returned by jQuery.ajax() implement the Promise interface, giving them all the properties, methods, and behavior of a Promise (see Deferred object for more information)

写的previous code更适当的方式可能是如下:

A more proper way to write the previous code could be as follow:

var promise = $.ajax({
  url: "/ajax",
  type: "POST",
  data: {
    _xsrf: xsrf_token,
    'action': "/document/x",
    'values': JSON.stringify(values)
  }
});

promise.done(function () {
  console.log("done!");
  window.location.reload();
});

promise.fail(function (jqXHR, textStatus) {
  console.log(jqXHR);
});

或者,如果你想使用 jQuery.when()

$.when(
  $.ajax({
    url: "/ajax",
    type: "POST",
    data: {
      _xsrf: xsrf_token,
      'action': "/document/x",
      'values': JSON.stringify(values)
    }
  })
).then(
  function done() {
    console.log("done!");
    window.location.reload();
  },
  function fail(jqXHR, textStatus) {
    console.log(jqXHR);
  }
);

我鼓励你阅读提供的链接。

I encourage you to read the links provided.

快乐阅读,快乐conding!

这篇关于在Firefox的jQuery阿贾克斯失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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