I am new to angularJS
, and for a start, I thought to develop a new application using only AngularJS
.
I am trying to make an AJAX
call to the server side, using $http
from my Angular App.
For sending the parameters, I tried 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 near, $.param
. For removing dependency on jQuery
, I tried,
data: {username: $scope.userName, password: $scope.password}
But this seemed to fail. Then I tried params
:
params: {username: $scope.userName, password: $scope.password}
But this also seemed to fail. Then I tried 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.?
$http({method: 'post', url: URL, data: {username: $scope.userName, password: $scope.password}});
– Mritunjay Jul 12 '14 at 7:06$scope.userName
defined? why didn't you trydata: data
? – Kevin B Jul 12 '14 at 7:12