Ajax未从调用中获得响应

我尝试了很多方法,但没有得到回应。我正在尝试从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

转载请注明出处:http://www.fymidi.com/article/20230526/1404534.html