提交表单时保持表单 window 打开
Keep form window open when form is submitted
当用户点击 link.
时,考虑此图像是一个 iframe window
我的问题
当用户点击存款时,表单被提交并且window关闭,因此用户不知道是否存款成功与否。
我想做什么
我正在寻找一种方法,在提交表单后保持 iframe window 打开,以显示适当的消息
表格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 打开,将不胜感激。
您需要更改表单提交才能使用 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));
当用户点击 link.
时,考虑此图像是一个 iframe window我的问题
当用户点击存款时,表单被提交并且window关闭,因此用户不知道是否存款成功与否。
我想做什么
我正在寻找一种方法,在提交表单后保持 iframe window 打开,以显示适当的消息
表格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 打开,将不胜感激。
您需要更改表单提交才能使用 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));