I am new to AngularJS, and for a start, I thought to develop a new application using only AngularJS.
(我是AngularJS的新手,一开始,我想只使用AngularJS开发一个新的应用程序。)
I am trying to make an AJAX call to the server side, using $http
from my Angular App.
(我正在尝试使用Angular App中的$http
向服务器端进行AJAX调用。)
For sending the parameters, I tried the following:
(为了发送参数,我尝试了以下操作:)
$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);
});
This is working, but it is using jQuery as well at $.param
.
(这是可行的,但它也在$.param
使用jQuery。)
For removing the dependency on jQuery, I tried:(为了消除对jQuery的依赖,我尝试:)
data: {username: $scope.userName, password: $scope.password}
but this seemed to fail.
(但这似乎失败了。)
Then I tried params
:(然后我尝试了params
:)
params: {username: $scope.userName, password: $scope.password}
but this also seemed to fail.
(但这似乎也失败了。)
Then I tried JSON.stringify
:(然后我尝试了JSON.stringify
:)
data: JSON.stringify({username: $scope.userName, password: $scope.password})
I found these possible answers to my quest, but was unsuccessful.
(我找到了这些可能的答案,但未成功。)
Am I doing something wrong?(难道我做错了什么?)
I am sure, AngularJS would provide this functionality, but how?(我敢肯定,AngularJS将提供此功能,但是如何?)
ask by Veer Shrivastav translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…