I need to translate this curl request to AJAX format curl -X GET --header 'Accept: application/xml' --header 'Authorization: Basic eGZlZG9yMDNAc3R1ZC5maXQudnV0YnIuY3o6YXVkZWxpdmVy' 'http://example.com/user'
I made
$.ajax({
type: "GET",
url: "http://example.com/user",
dataType: "xml",
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "application/xml");
xhr.setRequestHeader("Authorization", "Basic eGZlZG9yMDNAc3R1ZC5maXQudnV0YnIuY3o6YXVkZWxpdmVy");
},
success: function(data){
console.log(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
This request returns "XMLHttpRequest cannot load http://example.com/user. Response for preflight has invalid HTTP status code 404.". Can somebody advise me on this ?
I don't know exactly why, but this doesn't work in pure javascript code (meaning something like running script.js) but it works in chrome extensions, when you put server you are trying to connect in permissions.