Skip to content

Instantly share code, notes, and snippets.

@daffl
Created February 28, 2014 17:24
Show Gist options
  • Select an option

  • Save daffl/9275397 to your computer and use it in GitHub Desktop.

Select an option

Save daffl/9275397 to your computer and use it in GitHub Desktop.
A prefilter that allows to send your CanJS model as JSON
can.ajaxPrefilter(function(options, originalOptions) {
// Change ContentType to application/json for POST and PUT
if(options.processData && !(/^application\/json((\+|;).+)?$/i.test(options.contentType)) && /^(post|put|delete)$/i.test(options.type)) {
options.contentType = "application/json";
options.data = JSON.stringify(originalOptions.data);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment