最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CORS synchronous requests not working in firefox - Stack Overflow

programmeradmin0浏览0评论

The official documentation of jQuery ( async ajax section ) says that:

Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation.

However this works in all recent browsers but firefox version >= 20. Here is the type of calls i'm making:

$.ajax({
      type : "GET",
      async: false,
      dataType : "text",
      url : link,
      xhrFields: { withCredentials: true },

      success: function(response){
         console.log("success ");
      },
        error: function(error){
            console.error(error);               
        }  
});

Does anyone have a clue why this is happening ?

UPDATE: Ive tested both with jQuery and vanilla XHR the error is always the same

[Exception... "A parameter or an operation is not supported by the underlying object" code: "15" nsresult: "0x8053000f (InvalidAccessError)"

The official documentation of jQuery ( async ajax section ) says that:

Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation.

However this works in all recent browsers but firefox version >= 20. Here is the type of calls i'm making:

$.ajax({
      type : "GET",
      async: false,
      dataType : "text",
      url : link,
      xhrFields: { withCredentials: true },

      success: function(response){
         console.log("success ");
      },
        error: function(error){
            console.error(error);               
        }  
});

Does anyone have a clue why this is happening ?

UPDATE: Ive tested both with jQuery and vanilla XHR the error is always the same

[Exception... "A parameter or an operation is not supported by the underlying object" code: "15" nsresult: "0x8053000f (InvalidAccessError)"

Share Improve this question edited May 21, 2013 at 14:03 mfreitas asked May 21, 2013 at 10:59 mfreitasmfreitas 2,4053 gold badges32 silver badges42 bronze badges 6
  • 1 You're not using dataType: "jsonp", so it must be the cross domain part, but you haven't showed us from where/to where this request is being made. – tandrewnichols Commented May 21, 2013 at 11:06
  • What does happen in FF? What does the network inspector tell you? – Bergi Commented May 21, 2013 at 11:12
  • @tandrewnichols Im using CORS in order to make cross-domain requests. – mfreitas Commented May 21, 2013 at 11:34
  • @Bergi in the network inspector tab its not showing any request. – mfreitas Commented May 21, 2013 at 11:34
  • I need to have synchronous requests while using CORS, if i remove async:false the request is made with success. – mfreitas Commented May 21, 2013 at 11:43
 |  Show 1 more comment

1 Answer 1

Reset to default 18

Use beforeSend instead of xhrField.

$.ajax({
    type : "GET",
    async: false,
    dataType : "text",
    url : link,
    beforeSend: function(xhr) {
      xhr.withCredentials = true;
    },
    success: function(response){
      console.log("success ");
    },
    error: function(error){
      console.error(error);               
    }
});
发布评论

评论列表(0)

  1. 暂无评论