Jquery ajax requests works fine in IE but it gives a below error in chrome
XHR failed loading: OPTIONS http://someurl/ send @ jquery.min.js:2 ajax @ jquery.min.js:2 (anonymous) @ index.html:6 event after adding below parameters header
$.ajax({ beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic " + btoa("user" + ":" + "passoword")); }, url: 'url', type: 'get', contentType:'text/html', headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'OPTIONS, HEAD, GET, POST, PUT, DELETE' }, success: function( data, textStatus, jQxhr ){ alert(data); $('#idc').html( data ); }, error: function( xhr, textStatus, errorThrown ){ alert(errorThrown+xhr.status+textStatus); } }); Application uses basic authentication and it works fine in ie but in chrome it is not picking the credentials and redirecting to other url where credentials needs to be entered. I gone through all the urls in stackoverflow but nothing worked
Acces Control Allow OriginandAccess Control Allow Methodsare meant to be implemented serverside, and not to be included in the Request headers of your AJAX.'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT',in the backend on the server side?ajax request, without it, and only with the respond, it's difficult to guess what's going on.headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'OPTIONS, HEAD, GET, POST, PUT, DELETE' },putting this in your request makes no sense. Only the server can set these options. They belong in the response, not the request. Check the MDN documentation for these headers, it mentions they are server-only headers. Only the server gets to decide what methods it accepts, and what origins it allows CORS for. You, as the caller, can't decide that - or else what would be the purpose of CORS at all?headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'OPTIONS, HEAD, GET, POST, PUT, DELETE' },which will create preflights that are not working with AUTH