PHP邮件提交表单,无需刷新
我正在使用插件发送电子邮件。我遇到的问题是,我不想在从模板提交表单后刷新页面,该模板在主页上的表单操作中调用。有人知道如何使用这个插件来实现这一点吗?我认为这可能有点帮助: 首先,您需要编辑包含表单的html页面。 然后将此脚本添加到其中并进行适当调整PHP邮件提交表单,无需刷新,php,phpmailer,Php,Phpmailer,我正在使用插件发送电子邮件。我遇到的问题是,我不想在从模板提交表单后刷新页面,该模板在主页上的表单操作中调用。有人知道如何使用这个插件来实现这一点吗?我认为这可能有点帮助: 首先,您需要编辑包含表单的html页面。 然后将此脚本添加到其中并进行适当调整 // this is the id of the form $("#idForm").submit(function(e) { e.preventDefault(); // avoid to execute the actual subm
// this is the id of the form
$("#idForm").submit(function(e) {
e.preventDefault(); // avoid to execute the actual submit of the form.
var form = $(this);
var url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
});
如果您不刷新页面,您将需要在后台使用ajax,因为如果您向服务器发送请求,则等待响应,即使用新内容刷新。使用ajax.Hi@Hussein,在ajax之后保留preventDefault(),它应该在var form之前