Created
October 1, 2015 01:33
-
-
Save jcguarinpenaranda/7be34360f376e7045ece to your computer and use it in GitHub Desktop.
Angular JS http post fix
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
.config(['$httpProvider', function ($httpProvider) { | |
// Intercept POST requests, convert to standard form encoding | |
$httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded"; | |
$httpProvider.defaults.transformRequest.unshift(function (data, headersGetter) { | |
var key, result = []; | |
if (typeof data === "string") | |
return data; | |
for (key in data) { | |
if (data.hasOwnProperty(key)) | |
result.push(encodeURIComponent(key) + "=" + encodeURIComponent(data[key])); | |
} | |
return result.join("&"); | |
}); | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment