我这里有一个奇怪的问题。 contact_p.php 页面会针对 contact.php 表单页面上输入的所有无效数据正确发送所有错误消息。所以我可以在页面上用红色框和文字打印它们。
成功执行脚本后,contact_p.php 页面也会向我发送成功消息。我可以在 contact.js 页面上使用提醒(数据); 检查成功状态和消息。
但由于某种原因,它不会在绿色框和文本中打印成功消息。我的意思是它根本不打印成功消息。
我试图解决这个错误几个小时,但还没有成功。请告诉我在导致这个奇怪问题的页面上我做了什么错误。
contact.php
<form name="FormPRegister" id="FormPRegister" novalidate>
<div class="control-group form-group">
.
.
other fields like Name, Mail, Phone, captcha etc
.
.
<div id="success"></div>
<!-- For success/fail messages -->
<button type="submit" class="btn btn-primary" tabindex="9">Send Message</button>
</div>
contact.js
success: function(data)
{
//alert(data);
var $responseText=JSON.parse(data);
if($responseText.staus == 'SUC')
{
// Success message
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-success').append("<strong> " + $responseText.message + " </strong>");
$('#success > .alert-success').append('</div>');
//clear all fields
$('#FormPRegister').trigger("reset");
}
else if($responseText.status == 'ERR')
{
// Fail message
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-danger').append("<strong> " + $responseText.message + " ");
$('#success > .alert-danger').append('</div>');
}
},
contact_p.php
if( Invalid data then do this )
{
$response['status']='ERR';
$response['message']= "Invalid Secrete Code!";
echo json_encode($response);
return;
}
if( Valid data then do this )
{
$response['status']='SUC';
$response['message']= "Inquiry submitted successfully";
echo json_encode($response);
return;
}
答案 0 :(得分:1)
我认为这是由于输入错误。 你有JS代码
Location
而不是
if($responseText.staus == 'SUC')
你能纠正并重试吗? 你有没有像Firebug这样的JS调试器吗?
编辑:不要忘记在重试之前重新加载缓存:例如,在Firefox上使用ctrl + shift + R.
答案 1 :(得分:1)
你在这里错误拼写状态:
if($responseText.staus == 'SUC')
它应该是:
if($responseText.status == 'SUC')