Angular $ http帖子提供了错误的请求

时间:2014-07-02 00:27:13

标签: javascript angularjs

我工作的第一个功能,并且无错误地发布到服务:

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;
    }

//第二次函数调用

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

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

当我这样做时:

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;

        };

我得到了一个糟糕的请求。所以我查看chrome dev工具中的标题,我看到表单数据:

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

当我查看表单数据时,我看到的工作方式是:

editorVersion:1.0.0.0
previewPubFile:123a7agfhff3bbb2ffbb

为什么发布角度方式的表单数据与jQuery方式不同,修复它的最简单方法是什么?

0 个答案:

没有答案