Bug Tracker

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);

}

});

Change History (1)

comment:1 Changed 9 years ago by m_gol

Resolution: migrated
Status: newclosed
Note: See TracTickets for help on using tickets.