Skip to content

Instantly share code, notes, and snippets.

@intruxxer
Created November 27, 2013 07:04
Show Gist options
  • Save intruxxer/7671739 to your computer and use it in GitHub Desktop.
Save intruxxer/7671739 to your computer and use it in GitHub Desktop.
$("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