Reputation: 4443
I am trying to add header to ajax request.
I use setRequestHeader but it do nothing. I can look in firefox that request headers doesnot contains Authentication! What i am doing wrong?
And how to add header?
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://test/test.svc/news",
dataType: "json",
beforeSend : function(xhr) {
xhr.setRequestHeader("Authentication", "Basic " + Base64.encode(username + ":" + password))
},
success: function(data) {
alert('Success');
},
error: function() {
alert("Loading data error...");
}
});
}
Upvotes: 2
Views: 2718
Reputation: 50976
Try username and password instead
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://test/test.svc/news",
dataType: "json",
username: 'username', /* not user */
password: 'pass',
success: function(data) {
alert('Success');
},
error: function() {
alert("Loading data error...");
}
});
}
username - A username to be used in response to an HTTP access authentication request
Upvotes: 4