单击按钮后AJAX调用未触发

时间:2018-04-06 17:48:58

标签: javascript jquery

单击按钮后,我的AJAX呼叫不会被触发,但是如果我快速点击该按钮三到四次,它就会起作用。

我在那里进行了验证,如果触发了它,它只需点击一下即可。

我的代码如下:



$(document).ready(function() {

  $('.FIRST_BTN').off().click(function() {
    //var id = $(this).attr("id");
    //alert("id is: " + id);
    var first_name = $("#first_name_main").val();
    var last_name = $("#last_name_main").val();
    var tech_id = $("#tech_id_main").val();
    var phone = $("#phone_main").val();
    var email = $("#email_main").val();
    if (first_name == '') {
      refresh2();
    } else if (last_name == '') {
      refresh2();
    } else {
      $.ajax({
        url: 'student_signup.php?action=tech_id',
        method: 'POST',
        data: {
          first_name: first_name,
          last_name: last_name,
          tech_id: tech_id,
          phone: phone,
          email: email
        },
        async: false,
        success: function(data) {
          $('#details').html(data);
          $('#myModal').modal('show');
          //refresh();
        }
      });
    }
  });

});


function refresh() {
  window.location.href = "student_signup.php";
}

function refresh2() {
  window.location.href = "student_signup.php?action=invalid";
}

<button class='btn btn-primary FIRST_BTN' type='button' name='FIRST_BTN' id='FIRST_BTN'>Submit</button>
&#13;
&#13;
&#13;

0 个答案:

没有答案