Skip to content

Instantly share code, notes, and snippets.

@YurkoHoshko
Last active August 29, 2015 14:14
Show Gist options
  • Save YurkoHoshko/f9b91ca19302f6bb417c to your computer and use it in GitHub Desktop.
Save YurkoHoshko/f9b91ca19302f6bb417c to your computer and use it in GitHub Desktop.
Sample ajax call
json_data = {sample: parameter}
$.ajax({
type: 'GET',
url: '/example/url',
data: json_data,
dataType: 'json',
beforeSend: addCsrfToken,
success: function( data ) {
//Do something with data on success;
},
error: function( data ) {
//Handle error;
},
completed: function() {
//Handle end of call execution;
}
});
function addCsrfToken(xhr){
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment