我正在使用以下代码通过ajax发送表单
<script>
$(document).ready(function(){
$("#update-settings").submit(function(e) {
var url = "files/jquery-pages/page_jquery_settings.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#update-settings").serialize(), // serializes the form's elements.
success: function(data)
{
$("#success-settings").hide().html(data).fadeIn('slow');
}
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
});
</script>
<div id="success-settings"></div>
到目前为止这个工作正常。
我的php页面像这样:
<?php
if(isset($_POST['change_password']) == $settings_btn_change_password)
{
echo "The password has been changed";
}
if(isset($_POST['update_email']) == $settings_btn_update_email)
{
echo "This is email update";
}
?>
以下是表格:
<form method="post" action="" name="update-settings" id="update-settings">
<div class="row">
<div class="col-md-12">
<input type="submit" value="<?php echo $settings_btn_change_password;?>" name="change_password" class="button_blue_standard pull-right">
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="submit" value="<?php echo $settings_btn_update_email;?>" name="update_email" class="button_blue_standard pull-right">
</div>
</div>
</form>
问题是,当我点击提交按钮更改密码示例时,它显示“密码已更改”和“这是电子邮件更新”。
如果我按下该按钮,我只想显示“密码已被更改”。
任何想法为什么?
Cheerz :)
答案 0 :(得分:0)
isset
无法与==
一起使用。所以请这样使用。
<?php
if(isset($_POST['change_password']))
{
echo "The password has been changed";
}
if(isset($_POST['update_email']))
{
echo "This is email update";
}
?>
答案 1 :(得分:0)
试试这个
<?php
if((isset($_POST['change_password'])) && ($settings_btn_change_password==$_POST['change_password']))
{
echo "The password has been changed";
}
if((isset($_POST['update_email'])) && ($settings_btn_update_email==$_POST['update_email']))
{
echo "This is email update";
}
?>
我希望它会有所帮助
答案 2 :(得分:0)
请使用&#39;退出;&#39;在每个echo语句之后。所以它应该是这样的: -
<?php
if(isset($_POST['change_password']) == $settings_btn_change_password)
{
echo "The password has been changed";
exit;
}
if(isset($_POST['update_email']) == $settings_btn_update_email)
{
echo "This is email update";
exit;
}
?>
答案 3 :(得分:0)
我在工作,所以我没有时间测试这个,但尝试:
if(isset($_POST['change_password']) && $_POST['change_password'] == $settings_btn_change_password) {
echo "The password has been changed";
exit();
} else if(isset($_POST['update_email']) && $_POST['update_email'] == $settings_btn_update_email) {
echo "This is an email update";
exit();
} else {
echo "Action not successfully carried out, try again";
error_log("There's an issue here, check it out");
}