i am using HTTP Basic Auth on my Webserver. Now i want to call a PHP Script via jQuery. Without Basic Auth it works fine but with Basic Auth activated the Browser shows a login prompt. For me it seems like the Auth Parameters were not transmitted correctly?! Any ideas?
Here my js:
var username = [USER];
var password = [PASSWORD];
$.ajax
({
type: "GET",
url: "[URL]/[Script].php?callback=?",
dataType: 'json',
headers: {
"Authorization": "Basic " + btoa(username +":"+ password)
},
success: function(result){
alert('Yeah!');
},
error: function(er){
alert('error!' +er);
}
});
edit, but also dont work :/
$.ajax
({
type: "GET",
url: "[URL]/[Script].php?callback=?",
dataType: 'json',
async: false,
xhrFields: {
withCredentials: true
},
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
},
success: function(result){
alert("YEY");
},
error: function(er){
alert('error!' +er);
}
});
No Auth: http://fs5.directupload.net/images/161220/izy9yqdh.jpg
correct Auth: http://fs5.directupload.net/images/161220/nkh6ybts.jpg
direct php call: http://fs5.directupload.net/images/161220/xvo4rry9.jpg