Skip to content

Instantly share code, notes, and snippets.

@Guley
Last active July 30, 2018 06:09
Show Gist options
  • Save Guley/cf36d05a0e0837d05ea7931214e6b68d to your computer and use it in GitHub Desktop.
Save Guley/cf36d05a0e0837d05ea7931214e6b68d to your computer and use it in GitHub Desktop.
Jquery Ajax With Authorization
var postvalues = {
"key": 'test',
"id": 1
};
$.ajax({
url: 'http://www.example.com/check/',
type: 'POST',
dataType: "json",
data: postvalues,
crossDomain:true,
beforeSend: function(xhr, settings){
xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
},
success: function(json) {
console.log(json)
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus, errorThrown);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment