jquery ajax请求因chrome中的错误而失败(使用async:false),但在FF中有效

时间:2012-12-11 15:09:17

标签: google-chrome firefox jquery xmlhttprequest

尝试用jQuery构建一个简单的AJAX请求。这是coffeescript:

$('#ad_id_string').blur(function() {
    var self, idString, adURL;
    self = $(this);
    if (self.val() != "") {
      idString = self.val();
      adURL = "/advertisements/" + idString;
      $.ajax({
        url: adURL,
        type: "GET",
        dataType: "json",
        data: "",
        async: false,
        contentType: "application/json",
        success: function(response, textStatus, jqXHR) {
          console.log(response);
        },
        error: function(jqXHR, textStatus, errorThrown) {
          console.log("Failed - " + textStatus + " : " + errorThrown);
        }
      });
    }
});

Firefox执行请求没有问题,并按预期返回JSON。但是,Chrome拒绝发送请求。相反,它会出现此错误:NETWORK_ERR: XMLHttpRequest Exception 101

我已尝试设置async:true而不是false,并同时删除async参数。这只会导致chrome在发送之前使请求失败而没有任何错误。我的Q / A人员将在Chrome或Safari中对此进行测试,因此需要在这些浏览器中使用。

1 个答案:

答案 0 :(得分:0)

看起来这与我的Chrome版本(23.0.1271.97)和相关网址有关。我正在使用Rails,因此我遇到了http://localhost:3000,而Chrome在传递带端口号的AJAX请求方面存在问题。

相关问题