Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CORS synchronous requests not working in firefox

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)"

like image 839
mfreitas Avatar asked May 21 '13 10:05

mfreitas


1 Answers

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);               
    }
});
like image 100
Diogo Cardoso Avatar answered Nov 09 '22 22:11

Diogo Cardoso