【发布时间】:2017-12-24 14:09:22
【问题描述】:
我尝试了很多事情,但没有得到回应。 我正在尝试从 mydomin/token 检索令牌,并且它响应良好。我调试了它并且它工作正常,但 Ajax 没有得到响应。 我正在使用这个
<script>
//working but not getting response
function myFunction1() {
$.ajax({
type: "GET",
url: "/Account/CheckLogin?Email=" + $("#username").val()
+ "&password=" + $("#password").val(),
success: function (data) {
alert(data);
}
}).done(function (data) {
alert(data);
}).fail(showError);
}
</script>
这是我的服务器代码
[HttpGet]
public JsonResult CheckLogin(Account account)
{
Result obj = new Result();
if (!account.Equals( null))
{
System.Diagnostics.Debug.Write(account.Email);
System.Diagnostics.Debug.Write(account.Password);
var result = db.Users.Any(x => (x.Username.Equals(account.Email) || x.Email.Equals(account.Email)) && x.Password.Equals(account.Password));
if (result)
{
//return RedirectToAction("Index", "Home");
obj.txt = true;
return Json(obj,JsonRequestBehavior.AllowGet);
}
}
obj.txt = false;
return Json(obj, JsonRequestBehavior.AllowGet);
}
我在浏览器和邮递员中得到的响应是
{
txt: false
}
但是 ajax 没有对未显示警报的数据给出任何响应。即使我这样做是为了确保但没有显示任何警报
success: function (data) {
alert("Hi");
}
我关注了这个和堆栈上的其他一些链接,但对我没有用。 how to call controller action in ajax url
【问题讨论】:
-
将 dataType: 'json' 添加到您的 ajax 调用中
-
你是怎么调用
myFunction1函数的?
标签: javascript jquery ajax asp.net-mvc response