Php 使用ajax提交时返回html
现在,我知道有几个问题看起来像这样,但简而言之,我还没有找到我需要的功能,更不用说让它工作了。我希望从我的站点页脚中的表单发送的消息返回确认消息,而不是将用户返回到新页面 默认状态 消息发送后 形式 理论上,这将调用文件Php 使用ajax提交时返回html,php,ajax,forms,Php,Ajax,Forms,现在,我知道有几个问题看起来像这样,但简而言之,我还没有找到我需要的功能,更不用说让它工作了。我希望从我的站点页脚中的表单发送的消息返回确认消息,而不是将用户返回到新页面 默认状态 消息发送后 形式 理论上,这将调用文件parse.php,该文件验证信息,与数据库一起工作,并发送mail函数。我遇到的问题是,页面返回的表单为空,没有警报,我也没有收到任何其他类型的响应(phpheader('Location:http://google.com)等) 我想知道的是,我的javascript是否
parse.php
,该文件验证信息,与数据库一起工作,并发送mail
函数。我遇到的问题是,页面返回的表单为空,没有警报,我也没有收到任何其他类型的响应(phpheader('Location:http://google.com)
等)
我想知道的是,我的javascript是否有问题,或者是因为我的表单需要更多的参数(method
,enctype
…)首先。
您的htmlid
中缺少元素,请使用以下命令:
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" id="submit_button" value="Submit button" /> //here set the id to element
</form>
首先重定向到另一页。
您的htmlid
中缺少元素,请使用以下命令:
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" id="submit_button" value="Submit button" /> //here set the id to element
</form>
首先重定向到另一页。
您的htmlid
中缺少元素,请使用以下命令:
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" id="submit_button" value="Submit button" /> //here set the id to element
</form>
首先重定向到另一页。
您的htmlid
中缺少元素,请使用以下命令:
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" id="submit_button" value="Submit button" /> //here set the id to element
</form>
要重定向到另一页工作解决方案:
表格
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" value="Submit button" />
</form>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function()
{
$('form').submit(function()
{
$.get('parse.php', $(this).serialize(), function(data)
{
$('#content').html(data);
}
return false;
}
}
</script>
$(文档).ready(函数()
{
$('form')。提交(函数()
{
$.get('parse.php',$(this).serialize(),函数(数据)
{
$('#content').html(数据);
}
返回false;
}
}
parse.php
if( isset($_REQUEST['field1']) and
isset($_REQUEST['field2']) and
isset($_REQUEST['field3']) )
{
// Headers and other parameters
$sujet = "Email Subject line";
$mailto = "my@email.com";
$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8"."\r\n";
$headers .= "From: " . $from . "\r\n";
$headers .= "Organization: ACNE CO.\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$message = "";
// Info to send
$field1 = $_REQUEST['field1'];
$field2 = $_REQUEST['field2'];
$field3 = $_REQUEST['field3'];
$message .= "Field 1 description: " . $field1 . "<br />";
$message .= "Field 2 description: " . $field2 . "<br />";
$message .= "Field 3 description: " . $field3 . "<br />";
mail($mailto, $sujet, $message, $headers);
// Confirmation message
$confirmation = '<div id="confirmation">Message sent</div>';
print($confirmation);
}
if(isset($\u请求['field1'])和
isset($_请求['field2'])和
isset($\u请求['field3']))
{
//标题和其他参数
$sujet=“电子邮件主题行”;
$mailto=”my@email.com";
$headers=“”;
$headers.=“MIME版本:1.0\r\n”;
$headers.=“内容类型:text/html;字符集=UTF-8”。\r\n”;
$headers.=“From:”.$From.\r\n”;
$headers.=“组织机构:公司。\r\n”;
$headers.=“X优先级:3\r\n”;
$headers.=“X-Mailer:PHP”.phpversion()。”\r\n”;
$message=“”;
//要发送的信息
$field1=$_请求['field1'];
$field2=$_请求['field2'];
$field3=$_请求['field3'];
$message.=“字段1说明:”.$field1.“
”;
$message.=“字段2说明:”.$field2.“
”;
$message.=“字段3说明:”.$field3.“
”;
邮件($mailto、$sujet、$message、$headers);
//确认信息
$confirmation='messagesent';
打印(确认);
}
工作解决方案:
表格
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" value="Submit button" />
</form>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function()
{
$('form').submit(function()
{
$.get('parse.php', $(this).serialize(), function(data)
{
$('#content').html(data);
}
return false;
}
}
</script>
$(文档).ready(函数()
{
$('form')。提交(函数()
{
$.get('parse.php',$(this).serialize(),函数(数据)
{
$('#content').html(数据);
}
返回false;
}
}
parse.php
if( isset($_REQUEST['field1']) and
isset($_REQUEST['field2']) and
isset($_REQUEST['field3']) )
{
// Headers and other parameters
$sujet = "Email Subject line";
$mailto = "my@email.com";
$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8"."\r\n";
$headers .= "From: " . $from . "\r\n";
$headers .= "Organization: ACNE CO.\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$message = "";
// Info to send
$field1 = $_REQUEST['field1'];
$field2 = $_REQUEST['field2'];
$field3 = $_REQUEST['field3'];
$message .= "Field 1 description: " . $field1 . "<br />";
$message .= "Field 2 description: " . $field2 . "<br />";
$message .= "Field 3 description: " . $field3 . "<br />";
mail($mailto, $sujet, $message, $headers);
// Confirmation message
$confirmation = '<div id="confirmation">Message sent</div>';
print($confirmation);
}
if(isset($\u请求['field1'])和
isset($_请求['field2'])和
isset($\u请求['field3']))
{
//标题和其他参数
$sujet=“电子邮件主题行”;
$mailto=”my@email.com";
$headers=“”;
$headers.=“MIME版本:1.0\r\n”;
$headers.=“内容类型:text/html;字符集=UTF-8”。\r\n”;
$headers.=“From:”.$From.\r\n”;
$headers.=“组织机构:公司。\r\n”;
$headers.=“X优先级:3\r\n”;
$headers.=“X-Mailer:PHP”.phpversion()。”\r\n”;
$message=“”;
//要发送的信息
$field1=$_请求['field1'];
$field2=$_请求['field2'];
$field3=$_请求['field3'];
$message.=“字段1说明:”.$field1.“
”;
$message.=“字段2说明:”.$field2.“
”;
$message.=“字段3说明:”.$field3.“
”;
邮件($mailto、$sujet、$message、$headers);
//确认信息
$confirmation='messagesent';
打印(确认);
}
工作解决方案:
表格
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" value="Submit button" />
</form>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function()
{
$('form').submit(function()
{
$.get('parse.php', $(this).serialize(), function(data)
{
$('#content').html(data);
}
return false;
}
}
</script>
$(文档).ready(函数()
{
$('form')。提交(函数()
{
$.get('parse.php',$(this).serialize(),函数(数据)
{
$('#content').html(数据);
}
返回false;
}
}
parse.php
if( isset($_REQUEST['field1']) and
isset($_REQUEST['field2']) and
isset($_REQUEST['field3']) )
{
// Headers and other parameters
$sujet = "Email Subject line";
$mailto = "my@email.com";
$headers = "";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8"."\r\n";
$headers .= "From: " . $from . "\r\n";
$headers .= "Organization: ACNE CO.\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$message = "";
// Info to send
$field1 = $_REQUEST['field1'];
$field2 = $_REQUEST['field2'];
$field3 = $_REQUEST['field3'];
$message .= "Field 1 description: " . $field1 . "<br />";
$message .= "Field 2 description: " . $field2 . "<br />";
$message .= "Field 3 description: " . $field3 . "<br />";
mail($mailto, $sujet, $message, $headers);
// Confirmation message
$confirmation = '<div id="confirmation">Message sent</div>';
print($confirmation);
}
if(isset($\u请求['field1'])和
isset($_请求['field2'])和
isset($\u请求['field3']))
{
//标题和其他参数
$sujet=“电子邮件主题行”;
$mailto=”my@email.com";
$headers=“”;
$headers.=“MIME版本:1.0\r\n”;
$headers.=“内容类型:text/html;字符集=UTF-8”。\r\n”;
$headers.=“From:”.$From.\r\n”;
$headers.=“组织机构:公司。\r\n”;
$headers.=“X优先级:3\r\n”;
$headers.=“X-Mailer:PHP”.phpversion()。”\r\n”;
$message=“”;
//要发送的信息
$field1=$_请求['field1'];
$field2=$_请求['field2'];
$field3=$_请求['field3'];
$message.=“字段1说明:”.$field1.“
”;
$message.=“字段2说明:”.$field2.“
”;
$message.=“字段3说明:”.$field3.“
”;
邮件($mailto、$sujet、$message、$headers);
//确认信息
$confirmation='messagesent';
打印(确认);
}
工作解决方案:
表格
<form>
<input type="text" name="field1" placeholder="Form field 1" />
<input type="text" name="field2" placeholder="Form field 2" />
<input type="text" name="field3" placeholder="Form field 3" />
<input type="submit" value="Submit button" />
</form>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function()
{
$('form').submit(function()
{
$.get('parse.php', $(this).serialize(), function(data)
{
$('#content').html(data);
}
return false;
}
}
</script>
$(文档).ready(函数()
{
$('form')。提交(函数()
{
$.get('parse.php',$(this).serialize(),函数(数据)
{
$('#content').html(数据);
}
返回false;