如何在没有jQuery的情况下用$http POST urlencoded表单数据?
我是AngularJS的新手,首先,我想只使用AngularJS开发一个新的应用程序。
我正在尝试使用我的Angular应用程序对服务器端进行AJAX调用。$http
为了发送参数,我尝试了以下操作:
$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。为了删除对jQuery的依赖性,我尝试了:$.param
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会提供这个功能,但是如何呢?