Javascript AngularJS http获取不向控制器传递任何内容

Javascript AngularJS http获取不向控制器传递任何内容,javascript,angularjs,Javascript,Angularjs,为什么函数登录(字符串电子邮件、字符串密码)电子邮件为空,而密码也为空 JavaScript: $http({ method: "GET", url: '/Home/Login/', dataType: "json", params: JSON.stringify({ email: 'Test', password: 'Test' }) }).success(function (data, status, headers, config) {

为什么函数
登录(字符串电子邮件、字符串密码)
电子邮件
为空,而
密码
也为空

JavaScript:

$http({
      method: "GET",
      url: '/Home/Login/',
      dataType: "json",
      params: JSON.stringify({ email: 'Test', password: 'Test' })
}).success(function (data, status, headers, config) {
      alert(data);
});
家庭控制器:

    public JsonResult Login(string email,string password)
    {
        return Json("working",JsonRequestBehavior.AllowGet);
    }

您的服务器希望参数作为查询参数,但您将作为JSON字符串发送。换线

params: JSON.stringify({ email: 'Test', password: 'Test' })

并删除
数据类型:“json”,

提示:正如@Phil&@Sateh所提到的,不要使用
success
error
方法,而是使用
then
方法。因此,您的代码将如下所示:

$http({
      method: "GET",
      url: '/Home/Login/',
      params: { email: 'Test', password: 'Test' }
}).then(function(response) {
      alert(response.data);
}, function() {
      console.log("Error occured");
});

您的服务器希望参数作为查询参数,但您将作为JSON字符串发送。换线

params: JSON.stringify({ email: 'Test', password: 'Test' })

并删除
数据类型:“json”,

提示:正如@Phil&@Sateh所提到的,不要使用
success
error
方法,而是使用
then
方法。因此,您的代码将如下所示:

$http({
      method: "GET",
      url: '/Home/Login/',
      params: { email: 'Test', password: 'Test' }
}).then(function(response) {
      alert(response.data);
}, function() {
      console.log("Error occured");
});

为什么您仍在使用?为什么您仍在使用?您不能用
then()
中相同的回调来替换
.success()
.error()
。每个人的论点完全不同;它是完整的
响应
对象,而不仅仅是
数据
您不能用
then()中相同的回调替换
.success()
.error()
。每个人的论点完全不同;它是完整的
响应
对象,而不仅仅是
数据