我正在尝试提交表单。表单是在html中我使用jquery将表单传递给php页面进行处理,json_encode将结果传回给用户显示。如果我尝试在php页面上添加一个incude xxx.php,jquery提交给它会杀死整个事情。
以下是它的展示方式: 这是主要的布局页面,包括您可以看到的表单
<form id="jq_forgot_password" class="forgot_password" action="" method="post" name="password_form">
<?PHP include 'widgets/recover_pass.php'; ?>
</form>
这是表单本身的内容:
<!-- Password Recovery Form-->
<div class="form_text">
<p>
<label for="email">Email:</label>
<input type="email" id="recover_email" name="recover_email" placeholder="Enter your email address" class="field_boarder" value="" size="25px" maxlength="255"/> </p>
<div class="login_button_container">
<input name="login_button" type="submit" class="login_button" value="Submit"/>
</div>
</div>
这是发布表单数据并阻止默认提交按钮刷新页面的jquery脚本:
// Forgot Password Validation and Post Function
$(function(){
$("#jq_forgot_password").submit(function(e){
e.preventDefault();
$.post("widgets/recover_pass_process.php", $("#jq_forgot_password").serialize(),
function(data){
if(data.email_check == 'invalid'){
$('div.message_error').hide();
$('div.message_success').hide();
$('div.message_error').fadeIn();
$('div.message_error').html("<div'> Sorry you must enter a valid e-mail address. Try again.</div>");
} else {
$('div.message_error').hide();
$('form#jq_forgot_password').hide();
$('div.message_success').fadeIn();
$('div.message_success').html("<div'>You're Password has been sent to" + data.email + ". Thank you </div>");
}
}, "json");
});
});
这是jquery提交功能提交的php文件:
<?php
$email_check = '';
$return_arr = array();
if(filter_var($_POST['recover_email'], FILTER_VALIDATE_EMAIL)) {
$email_check = 'valid';
}
else {
$email_check = 'invalid';
}
$return_arr["email_check"] = $email_check;
$return_arr["email"] = $_POST['recover_email'];
echo json_encode($return_arr);
?>
这一切都很好但是如果我在recover_pass_process.php的顶部添加一个include语句,如下所示:
<?php
include 'func/user.func.php';
$email_check = '';
$return_arr = array();
if(filter_var($_POST['recover_email'], FILTER_VALIDATE_EMAIL)) {
$email_check = 'valid';
}
else {
$email_check = 'invalid';
}
$return_arr["email_check"] = $email_check;
$return_arr["email"] = $_POST['recover_email'];
echo json_encode($return_arr);
?>
然后,即使包含的文件中没有任何内容,它也会突然停止。我试图包含另一个文件的事实就是杀死它。
我做错了什么???提前谢谢!!
答案 0 :(得分:0)
$("#jq_forgot_password").live("submit",function(e){
e.preventDefault();
$.post("widgets/recover_pass_process.php", $("#jq_forgot_password").serialize(),
function(data){
if(data.email_check == 'invalid'){
$('div.message_error').hide();
$('div.message_success').hide();
$('div.message_error').fadeIn();
$('div.message_error').html("<div'> Sorry you must enter a valid e-mail address. Try again.</div>");
} else {
$('div.message_error').hide();
$('form#jq_forgot_password').hide();
$('div.message_success').fadeIn();
$('div.message_success').html("<div'>You're Password has been sent to" + data.email + ". Thank you </div>");
}
}, "json");
});
试试这个..