Skip to content

Instantly share code, notes, and snippets.

@scriptonian
Forked from alikrc/ajaxBearer.js
Created May 11, 2018 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptonian/8a0977fd581201b5a50f7db409b0654e to your computer and use it in GitHub Desktop.
Save scriptonian/8a0977fd581201b5a50f7db409b0654e to your computer and use it in GitHub Desktop.
ajax post with bearer token
$.ajax({
url: "http://localhost:33460/api/Account/userinfo",
dataType: 'json',
data: {
foo: 'bar'
},
success: function(data, status) {
return console.log("The returned data", data);
},
beforeSend: function(xhr, settings) { xhr.setRequestHeader('Authorization','Bearer ' + tokenString ); } //set tokenString before send
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment