AngularJS:如何阻止自动添加引号来发布值在$http post请求中?

15 浏览
0 Comments

AngularJS:如何阻止自动添加引号来发布值在$http post请求中?

我刚接触AngularJS,并且为了开始,我想使用AngularJS开发一个新的应用程序。

我试图使用我的Angular应用程序中的$http进行服务器端的AJAX调用。

为了发送参数,我尝试了以下方法:

$http({
    method: "post",
    url: URL,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    data: $.param({username: $scope.userName, password: $scope.password})
}).success(function(result){
    console.log(result);
});

这样可以工作,但它还使用了jQuery的$.param。为了消除对jQuery的依赖,我尝试了:

data: {username: $scope.userName, password: $scope.password}

但是这似乎失败了。然后我尝试了params

params: {username: $scope.userName, password: $scope.password}

但是这也似乎失败了。然后我尝试了JSON.stringify

data: JSON.stringify({username: $scope.userName, password: $scope.password})

我找到了一些可能的答案来解决我的问题,但是没有成功。我是不是做错了什么?我相信,AngularJS会提供这个功能,但是该怎么做呢?

0