1

The first function that I have works and posts to the serve without error:

function SendHttpPostToURLEncodedForm(options) {
        var deferredResult = $q.defer();
        var pathToResource = UrlService.relativePathToRoot + options.url;
        $.ajax({
            'type': "POST",
            'url': pathToResource,
            'data': options.params,
            'traditional': true,
            'headers': {
                'Accept': "application/json",
                "Content-Type": "application/x-www-form-urlencoded"
            },
            'dataType': "json"
        })
            .then(function (result) {
                $rootScope.$apply(function () {
                    deferredResult.resolve({ 'data': result });
                });
            })
            .fail(function (reason) {
                $rootScope.$apply(function () {
                    deferredResult.reject(parseErrorMessage(reason));
                });
            });
        return deferredResult.promise;
    }

//second function call

var updateApplicationMetadata = function(appId, editorVersion, previewPubFile){

        var deferred = SendHttpPostToURLEncodedForm({
            url: '../resource/applications/' + appId,
            params: {
                editorVersion: editorVersion,
                previewPubFile: previewPubFile
            }
        });
        return deferred.promise;
        };

when I do:

var updateApplicationMetadata = function(appId, editorVersion, previewPubFile){
            var deferred = $q.defer(),
                appUpdate = $http({
                    method: 'post',
                    url: '../resource/applications/'+appId,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded','Accepts': 'application/json'},
                    data: {
                        editorVersion : editorVersion,
                        previewPubFile: previewPubFile
                    }
                })
            appUpdate.then(function(data){
                console.log('success');
                deferred.resolve(data)
            }).catch(function(reason){
                deferred.reject(reason);
            });
        return deferred.promise;

        };

I get a bad request. So I look at the headers in chrome dev tools and I see for form data:

{"editorVersion":"9.9.9","previewPubFile":"test"}:

When I look at the form data for the way that work I see:

editorVersion:1.0.0.0
previewPubFile:123a7agfhff3bbb2ffbb

Why is it that the form data for the angular way to post is different than the jQuery way, and what's the easiest way to fix it?

wootscootinboogie
  • 8,461
  • 33
  • 112
  • 197
  • possible duplicate of [How can I make angular.js post data as form data instead of a request payload?](http://stackoverflow.com/questions/11442632/how-can-i-make-angular-js-post-data-as-form-data-instead-of-a-request-payload) – Phil Jul 02 '14 at 00:33
  • The solution that I found for this way to $.params(dataToSend) and then it works fine. – wootscootinboogie Jul 02 '14 at 01:11

0 Answers0