Reputation: 919
I read various posts but could not figure out the solution. I am calling this url http://somesite.com/test.html and code in test.html is
$.ajax({
type: "GET",
url: "http://anothersite.com/app_dev.php/rest/123",
crossDomain: true,
async: false,
beforeSend: function (xhr){
alert('Befor Sent');
var text = btoa("11" + ":" + "22");
alert("Enc:" + text);
xhr.setRequestHeader("Authorization", "Basic " + text);
},
error: function(jqXHR, textStatus, errorThrown){
alert("errorThrown:" + errorThrown);
},
success: function (){
alert('Thanks for your comment!');
}
});
I get 401 error back and when I check headers there is no Authorization header
Upvotes: 1
Views: 577
Reputation: 919
The problem happens if the code is run on browser. I tried this for phonegap and it works perfectly.
Upvotes: 1