Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created December 26, 2016 15:47
Show Gist options
  • Save gelanivishal/f8a415d72a6a8afcc66b891205c9a5cc to your computer and use it in GitHub Desktop.
Save gelanivishal/f8a415d72a6a8afcc66b891205c9a5cc to your computer and use it in GitHub Desktop.
$.ajax({
url: "http://www.example.com/api",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
type: 'POST',
dataType: 'json',
contentType: 'application/json',
processData: false,
data: '{"foo":"bar"}',
success: function (data) {
alert(JSON.stringify(data));
},
error: function(){
alert("Cannot get data");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment