我正在为我的网站制作表单。表单标记的标记看起来像:
<form method="post" action="contactengine.php">
当用户提交表单时,表单使用action=" contactenengine .php"向我发送电子邮件,其中包含表单信息。但是,由于我的页面布局,当用户提交表单时,我不能重新加载页面。我该如何解决这个问题?
你能使用javascript + jquery吗?使用jquery进行异步发布相当简单。
$('#formid').submit(function({ //listens for form submission
$(this).preventDefault(); //stops the submission
$.post('actionPage.php', $(this).serialize, function(response){
//posts the data to actionpage.php, with the form data, and then runs a function handling the response.
});
}));
让服务器响应204 No Content
响应(spec)。
等如果客户端是一个用户代理,它不应该改变它的文档视图,从导致请求被发送。这个响应的主要目的是允许在不改变用户代理的活动文档视图的情况下输入操作。
:
<?php
http_response_code(204);
exit();