Ajax, prevent multiple request on click

前端 未结 10 2237
忘掉有多难
忘掉有多难 2020-11-28 04:10

I\'m trying to prevent multiple requests when user click on login or register button. This is my code, but it doesn\'t work. Just the first time works fine, then return fals

10条回答
  •  一整个雨季
    2020-11-28 04:59

    I've tried this and worked very fine for me, I was having trouble that $.ajax send more request until results return,

     var settings = {
        "url": "/php/auth/login.php",
        "method": "POST",
        "timeout": 0,
        "async": false,
        "headers": {
            "Content-Type": "application/json; charset=utf-8"
        },
        "data": jsondata, //data pass here is in JSON format
    };
    $.ajax(settings).done(function (ress) {
      try{
          console.log(ress, "Result from Ajax here");
        }
        catch(error){
          alert(error);
          console.log(ress);
        }
    });
    

    async : false worked for me. Thanks.

提交回复
热议问题