为什么在函数中Login(string email,string password)
email
为null,password
也为null。
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' })
至
params: { email: 'Test', password: 'Test' }
并删除 dataType: "json",
提示:就像提到的@Phil和@Sateh一样,不要使用success
或error
方法,而要使用then
method。因此,您的代码将如下所示:
$http({
method: "GET",
url: '/Home/Login/',
params: { email: 'Test', password: 'Test' }
}).then(function(response) {
alert(response.data);
}, function() {
console.log("Error occured");
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句