【发布时间】:2011-08-23 16:55:58
【问题描述】:
我试图在提交表单后将页面加载到模式窗口“checkout.php”中,但我需要它来加载表单的结果。通常,只需将表单的操作设置为 url 并传递数据,但在这种情况下,页面需要使用该数据加载到模式中,这需要使用比我知道的更多的 jQuery。
HTML
<form id="shippingform" name="shippingform" method="post" action="#">
<table id="box-table-a" width="25%" border="1">
<thead>
<tr>
<th scope="col" width="40%">USPS Option</th>
<th scope="col" width="40%">Price</th>
<th scope="col" width="20%" style="text-align: right;">Select</th>
</tr>
</thead>
<tbody>
<tr>
<td class="first">Ground:</td>
<td><?php echo "$" . sprintf("%01.2f", $groundTotal) ?></td>
<td class="last"><input name="shipping" type="radio" id="radio" value="<?php echo $groundTotal ?>" checked="checked" /></td>
</tr>
<tr>
<td class="first">Priority:</td>
<td><?php echo "$" . sprintf("%01.2f", $priorityTotal) ?></td>
<td class="last"><input type="radio" name="shipping" id="radio2" value="<?php echo $priorityTotal ?>" /></td>
</tr>
<tr>
<td class="first">Express:</td>
<td><?php echo "$" . sprintf("%01.2f", $expressTotal) ?></td>
<td class="last"><input type="radio" name="shipping" id="radio3" value="<?php echo $expressTotal ?>" /></td>
</tr>
</tbody>
</table>
<a href="#" onclick="totalCalc()">submit</a>
</form>
JS
<script language="javascript">
function totalCalc() {
$('#cartdialog').load("/ash/shop/checkout.php");
}
</script>
我上面的内容将在单击表单的提交按钮后将 checkout.php 页面加载到模式中。我不是在问为什么页面没有加载与表单一起发送的信息。我完全理解我在这里所做的只是执行一个函数来将“checkout.php”加载到模态的 div 中。我需要有人向我解释如何编辑我的函数,以便加载“checkout.php”,就像它是表单的操作一样,数据将被传递。
提前感谢您的帮助!
在下面编辑
<form id="shippingform" name="shippingform" method="post" action="#">
JS
$('#shippingform').submit(function(event){
var data = $(this).serialize();
$.post('/ash/shop/checkout.php', data)
.success(function(result){
$('#cartdialog').html(result);
})
.error(function(){
console.log('Error loading page');
})
return false;
});
CHECKOUT.PHP 页面将输入称为“运费”
<?php
//total up price of all items
$subtotal = ($subtotal + ($row_rsMyCart['price'] * $row_rsMyCart['quantity']));
$myTotal = ($subtotal + $_POST['shipping']);
} while ($row_rsMyCart = mysql_fetch_assoc($rsMyCart)); ?>
</table>
<p>
<?php
//development
echo "<br>";
echo "Subtotal: $" . sprintf("%01.2f", $subtotal);
echo "<br>";
echo "Total: $" . sprintf("%01.2f", $myTotal);
?>
</p>
【问题讨论】:
-
可能重复:stackoverflow.com/questions/1218245/… 问题不完全相同,但答案相同,这就是为什么我将其标记为重复。
标签: jquery forms load modal-dialog