你有这样的表格
<form id="newletterBoxForm" method="POST" action="[wordpress_plugin_directory]/subscribe.php">
<input type="text" ... />
<input type="text" ... />
<input type="submit" ... />
</form>
使用 jQuery,您将在事件开始之前获得事件并取消如下操作:
$(document).ready(function() {
$("#newletterBoxForm").on("submit", function() {
$.ajax({
type: "POST",
url: "[wordpress_plugin_directory]/subscribe.php.",
// get the data of your form
data: $(this).serialize(),
success: function (data) {
// if it is ok, do some actions
alert("ok DONE!")
},
error : function(s , i , error){
console.log(error);
}
});
// cancel normal behaviour which will refresh your page
return false;
});