Created
February 28, 2014 17:24
-
-
Save daffl/9275397 to your computer and use it in GitHub Desktop.
A prefilter that allows to send your CanJS model as JSON
This file contains hidden or 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
| 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