我是AngularJS的新成員。我想從角度控制器到我的MVC5控制器進行ajax調用。我行動與三個參數駐留在的HomeController像如何通過從angularJS控制器到MVC5控制器的ajax調用獲取JSON
public ActionResult addFrnd(int name, string phone, int age)
{
//do something
return json();
}
和我的角度控制器放在這裏
var myModule = angular.module("myApp", ['ngRoute']);
myModule.controller('SimpleController', function ($scope, $http, SimpleFactory) {
$scope.friends = [];
init();
function init() {
$scope.friends = SimpleFactory.getFriend();
}
$scope.addFriend = function ($http) {
$scope.friends.push(
{
name: $scope.newFriend.name,
phone: $scope.newFriend.phone,
age: $scope.newFriend.age
});
//$http("/Home/addFrnd");
$http.get({
type: "POST",
url: "~/Home/addFrnd",
data: {
name: $scope.newFriend.name,
phone: $scope.newFriend.phone,
age: $scope.newFriend.age
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function (msg) {
alert(msg.d);
}
});
};
});
我怎麼能解決這個問題?請幫助我
爲什麼你傳遞$ http服務的addFriend功能 – 2014-09-26 19:30:38