简体   繁体   中英

Ajax is not getting response from call

I have tried many things but not getting response from this. I am trying to retrieve token from mydomin/token and it is responding well. I debugged that and its working fine but Ajax is not taking the response. I am using this

<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>

Here is my server code

 [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);
        }

What i am getting response in browser and Post man is

{
txt: false
}

But ajax is not giving any response in data not showing alert. Even i did this to make sure but no alert not shown

 success: function (data) {
                alert("Hi");
            } 

I followed this and some other links on stack but didn't worked for me. how to call controller action in ajax url

如果看不到警报消息,则ajax调用不成功,请尝试从浏览器(chrome)中按f12调试它,并检查是否有任何错误,然后选择“网络”标签,然后滚动浏览对服务器的请求并找到由ajax调用创建的ajax调用,然后单击它,然后您将发现问题所在,如果失败,您应该可以在这里以红色找到您的ajax调用

My issue was I was trying to fire Ajax off the click event of a submit button that had a server side click event setup. I had to make the button just a simple button (ie )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM