I need to send a Get request with cross domain origin with header authentication.
Its working fine in Chrome and Firefox, but I'm having issues in Safari and IE. Also in random cases it returns 401.
<script>
var url = 'username:[email protected]';
$.ajax({
url: url,
dataType: 'jsonp',
jsonpCallback: "callback",
success: function(json) {
alert(json);
}
});
</script>
What would be the best option to solve this?
If I have understood the question correctly, you could use the beforeSend callback to add basic authentication on the request. This is irrelevant of jsonp or cross-origin though.
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
}
https://jsfiddle.net/rn9Lp304/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With