Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件提交表单,无需刷新_Php_Phpmailer - Fatal编程技术网

PHP邮件提交表单,无需刷新

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

我正在使用插件发送电子邮件。我遇到的问题是,我不想在从模板提交表单后刷新页面,该模板在主页上的表单操作中调用。有人知道如何使用这个插件来实现这一点吗?

我认为这可能有点帮助: 首先,您需要编辑包含表单的html页面。 然后将此脚本添加到其中并进行适当调整

// 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之前