How to pass username and password to web browser using jQuery ajax?
2 answers
Here is the doc for $. ajax . It also has many additional parameters. Follow the docs when you need something extra.
$.ajax({
type: 'POST',
url: 'https://webservice url',
data: ({ username: value, password: value; }) //use parameters as such defined in webservice
success: function(data){
}
})
+2
source to share
$.ajax({
type: 'GET',
url: 'url',
dataType: 'json',
//whatever you need
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', make_base_auth(user, password));
},
success: function () {});
});
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return 'Basic ' + hash;
}
+1
source to share