获取input的keyup或者input状态只获取一次值避免无限重复值

 $(document).ready(function () {
    // Select the text input field
    var textInput = $("#textInput");

    var delayTimer;

    // Attach an event handler to the input field for the "input" event
    textInput.on("input", function () {
      clearTimeout(delayTimer);
      delayTimer = setTimeout(function () {
        // Get the form data
        var formData = $("#myForm").serialize();

        // Send an Ajax request
        $.ajax({
          type: "POST",
          url: "your_php_script.php",
          data: formData,
          success: function (response) {
            // Update the result div with the response
            $("#result").html(response);
          },
          error: function (error) {
            console.error("Ajax request failed: " + error);
          }
        });
      }, 500); // Adjust the delay (in milliseconds) as needed
    });
  });

Check Also

js提交form数据的时候如果要包含file数据要用到FormData对象

通过创建一个FormData对 …

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注