当用户点击链接时,请考虑此图片是iframe窗口。
我的问题
当用户点击存款时,表单会被提交并 窗口关闭 ,因此用户不知道存款是否成功。
我想做什么
我正在寻找一种方法,在提交表单后保持iframe窗口打开,以显示相应的消息
表单HTML
<form name="depForm" action="" id="register_form" method="post">
User Name<br /><input type="text" name="uname" value="" /><br />
Credit Card Nr<br /><input type="text" name="cc" value="" /><br />
CSV Nr<br /><input type="text" name="csv" value="" /><br />
Amount<br /> <input type="text" name="amount" value="" /><br />
<input type="submit" value="deposit" name="deposit" class="buttono" />
</form>
PHP代码
if(isset($_POST['deposit'])){
if(isset($_SESSION['FBID'])){
$uid=$_SESSION['FBID'];
$amount = $_POST['amount'];
$cc = $_POST['cc'];
$csv = $_POST['csv'];
//new bal
$bal = getBal($uid);
$newBal = $bal+$amount;
$sql="UPDATE members SET balance='$newBal' WHERE member_nr='$uid'";
$result = mysql_query($sql) or die("error please try again");
if($result){
}
}
如果有人可以告诉我如何在表单提交后保持iframe打开,我们将不胜感激。
答案 0 :(得分:4)
您需要更改表单提交以使用AJAX。在响应中,您可以包含状态标志,以向UI指示请求是否成功并采取适当的行动。像这样:
$('#register_form').submit(function(e) {
e.preventDefault(); // stop the standard form submission
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function(data) {
if (data.success) {
// show success message in UI and/or hide modal
} else {
// it didn't work
}
},
error: function(xhr, status, error) {
// something went wrong with the server. diagnose with the above properties
}
});
});
$success = false;
if (isset($_POST['deposit'])) {
if (isset($_SESSION['FBID'])) {
$uid = $_SESSION['FBID'];
$amount = $_POST['amount'];
$cc = $_POST['cc'];
$csv = $_POST['csv'];
$bal = getBal($uid);
$newBal = $bal + $amount;
$sql = "UPDATE members SET balance='$newBal' WHERE member_nr='$uid'";
$result = mysql_query($sql) or die("error please try again");
if ($result) {
$success = true;
}
}
}
echo json_encode(array('success' => $success));