diff --git a/src/.jshintrc b/src/.jshintrc index 9500d330d7ab..55414b5b3fb8 100644 --- a/src/.jshintrc +++ b/src/.jshintrc @@ -51,6 +51,7 @@ "isWindow": false, "isScope": false, "isFile": false, + "isFormData": false, "isBlob": false, "isBoolean": false, "isPromiseLike": false, diff --git a/src/Angular.js b/src/Angular.js index c793999639af..d998b0f4fb05 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -45,6 +45,7 @@ isWindow: true, isScope: true, isFile: true, + isFormData: true, isBlob: true, isBoolean: true, isPromiseLike: true, @@ -566,6 +567,11 @@ function isFile(obj) { } +function isFormData(obj) { + return toString.call(obj) === '[object FormData]'; +} + + function isBlob(obj) { return toString.call(obj) === '[object Blob]'; } diff --git a/src/ng/http.js b/src/ng/http.js index c100594803ae..f9bbaa7e8d8d 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -142,7 +142,7 @@ function $HttpProvider() { // transform outgoing request data transformRequest: [function(d) { - return isObject(d) && !isFile(d) && !isBlob(d) ? toJson(d) : d; + return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d; }], // default headers diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index d388576f1e68..691542956ad5 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -991,6 +991,15 @@ describe('$http', function() { $http({ method: 'POST', url: '/url', data: blob }); }); + it('should ignore FormData objects', function() { + if (!window.FormData) return; + + var formData = new FormData(); + formData.append('angular', 'is great'); + + $httpBackend.expect('POST', '/url', '[object FormData]').respond(''); + $http({ method: 'POST', url: '/url', data: formData }); + }); it('should have access to request headers', function() { $httpBackend.expect('POST', '/url', 'header1').respond(200);