当单击该元素时,Ajax请求第一次加载数据,第一次阻止ajax请求

时间:2018-11-29 08:25:32

标签: javascript jquery ajax

  $.ajax({
        type: "POST",
        url: "/php/auth/login.php",
        data: $("#login-form").serialize(),
        success: function(msg) {
            //stuffs
        },
        complete: function() {
            $(this).data('requestRunning', false);
        }
    });  

1 个答案:

答案 0 :(得分:0)

使用一个标志,进行检查并将其设置为false

let shouldAjax = true;

// later
if (shouldAjax) {
  $.ajax({
    type: "POST",
    url: "/php/auth/login.php",
    data: $("#login-form").serialize(),
    success: function(msg) { //stuffs 

    },
    complete: function() {
      $(this).data('requestRunning', false);
      shouldAjax = false;
    }
  });
}