Prevent ajax call from firing twice

后端 未结 5 939
遥遥无期
遥遥无期 2020-12-05 20:20

I have an ajax call

$(\'#button1\').on(\'click\', function(e){
    $.ajax({
      url:  url,
      type: \'POST\',
      async: true,
      dataType: \'json\         


        
5条回答
  •  误落风尘
    2020-12-05 20:35

    I was facing the same issue and it works when I set async: false. Sample code will be like this

    $('#button1').on('click', function(e){
        $.ajax({
          url:  url,
          type: 'POST',
          async: false,
          dataType: 'json',
          enctype: 'multipart/form-data',
          cache: false,
          success: function(data){
    
          },
          error: function(){}
        });
    });
    

提交回复
热议问题