$(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对 …