Opened 9 years ago
Closed 9 years ago
#15189 closed bug (migrated)
Basic Authentication does not work with JSONP
Reported by: | driz | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | ajax | Version: | 1.11.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When sending Basic Authentication credentials with an jQuery AJAX request like so:
$.ajax({
type: 'GET', url: 'http://domain.com', beforeSend : function(xhr) {
var credentials = btoa(username + ':' + password); xhr.setRequestHeader("Authorization", "Basic " + credentials);
}, dataType: 'jsonp', success: function(data) {
console.log(data);
},
});
It doesn't work because the dataType is JSONP. Changing the dataType to JSON works.
However if you need to use JSONP for CORS, you have to do the following workaround:
$.ajax({
type: 'GET', url: 'http://username:password@domain.com', dataType: 'jsonp', success: function(data) {
console.log(data);
}
});
Migrated to https://github.com/jquery/jquery/issues/1781