Last active
August 29, 2015 14:17
-
-
Save barneycarroll/6836bdb13f00048f920b to your computer and use it in GitHub Desktop.
Avoid preflight OPTIONS conflicts when attempting to POST with a CORS XHR in Mithril. This only solves the use case of simple POST attempts with web clients other than Safari (which sets custom headers on CORS POST requests): it will not work for situations in which any custom headers are added to the request – in these cases an OPTIONS prefligh…
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
m.cors = 'FormData' in window ? function( request ){ | |
var input = request.data; | |
if( input ){ | |
delete request.data; | |
} | |
else { | |
return m.request( request ); | |
} | |
request.serialize = function(){ | |
var formData = new FormData(); | |
for( var key in input ){ | |
formData.append( key, input[ key ] ); | |
} | |
return formData; | |
} | |
return m.request( request ); | |
} : m.request; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment