Created
November 27, 2013 07:04
-
-
Save intruxxer/7671739 to your computer and use it in GitHub Desktop.
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
$("someElement").ajaxSend(function(e, xhr, options) { | |
var token = $("meta[name='csrf-token']").attr("content"); | |
xhr.setRequestHeader("X-CSRF-Token", token); | |
}); | |
$("someElement").click(function(){ | |
$.ajax( | |
{ | |
type: "POST", | |
url: "/products", | |
beforeSend: function( xhr ) { | |
xhr.overrideMimeType( "text/plain; charset=x-user-defined" ); | |
xhr.setRequestHeader("Accept", "text/javascript"); | |
}, | |
data: { product: { name: "Filip", description: "whatever" } }, | |
dataType: 'json', //xml, html, script, json | |
success: doSomethingSuccess(dataServer), | |
error: function( req, status, err ) { | |
console.log( 'something went wrong', status, err ); | |
}, | |
complete: alert('Done!') | |
}); | |
}); | |
function doSomethingSuccess(data){ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment