Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

withCredentials property is not supported in Firefox

I am using HTML5, jQuery 1.6.1, jQuery Mobile 1.0.1.

I am using below code to make an Ajax request. It's working fine in Chrome but I got the below error while testing in Firefox 14.0.1.

Use of XMLHttpRequest's withCredentials attribute is no longer supported in the synchronous mode in window context.

Code:

$.ajax({
   type: "GET",
   dataType: "json",        
   async: false,
   beforeSend: function (xhr){          
        xhr.setRequestHeader('Authorization', make_base_auth(UserId, Password)); 
  },
  xhrFields: {
      withCredentials: true
  },
   success:function(data){                  
   console.log("Success");          
 },
 error:function(xhr,err){
    console.log("Failed" );
 }          
});

Please help me out on this.

like image 617
Srikanth Chilukuri Avatar asked Dec 03 '22 02:12

Srikanth Chilukuri


1 Answers

The solution is simple : don't use async: false in $.ajax.

It's deprecated in newer version and you don't need it. It was always a bad idea to use it. Execute what you need to do with result from the success callback (just like your console.log).

From the documentation (1.8) :

Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the complete/success/error callbacks.

like image 162
Denys Séguret Avatar answered Dec 22 '22 19:12

Denys Séguret