Last active
August 29, 2015 14:14
-
-
Save YurkoHoshko/f9b91ca19302f6bb417c to your computer and use it in GitHub Desktop.
Sample ajax call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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