weixin_33691700 2015-10-22 07:02 采纳率: 0%
浏览 49

不需要的AJAX请求已发送

I am trying to send an AJAX request to login. Yesterday it was working perfectly but today when I send a request it sends one request perfectly but a second is unwanted. I'm stuck how to deal with this. Please help.

$('#login_form').submit(function(e) { 
    e.preventDefault();

    $.post("<?php echo base_url() ?>login/login_user",
        $(this).serializeArray(),
        function(data) {
            if (data == 0) {
                $(".user").show().delay(2000).fadeOut();
            } 

            if (data == "Epass") {
                $(".pass").show().delay(2000).fadeOut();  
            } 

            if (data == "admin" || data =="other") {
                $(".success").show().delay(2000).fadeOut();

                if (data == "admin") {
                    window.location.href = "<?php echo base_url() ?>dashboard";
                } else {
                    window.location.href = "<?php echo base_url() ?>index";
                }
            };
        });
    })

this is firebug result of ajax request

  • 写回答

2条回答 默认 最新

  • 零零乙 2015-10-22 07:05
    关注

    Set asynchronous to false, when you need that ajax request to be completed before the browser passes to other codes

     $.ajax(... async: false ...);
    
    评论

报告相同问题?