Javascript 在模式对话框中提交/更新子记录后更新父记录中的计算字段
在父窗体中使用bootstrap 3模式对话框提交/更新子记录时,更新父窗体的计算字段有点问题 我在Javascript 在模式对话框中提交/更新子记录后更新父记录中的计算字段,javascript,php,jquery,ajax,twitter-bootstrap,Javascript,Php,Jquery,Ajax,Twitter Bootstrap,在父窗体中使用bootstrap 3模式对话框提交/更新子记录时,更新父窗体的计算字段有点问题 我在parent.js文件中有这个函数: function update_lineitems_subtotal() { var qid = $j('[name=SelectedID]').val(); if (!isNaN(qid)) { $j.ajax({ url: 'hooks/ajax_quote_subtotal.php', data: {qid: qi
parent.js
文件中有这个函数:
function update_lineitems_subtotal() {
var qid = $j('[name=SelectedID]').val();
if (!isNaN(qid)) {
$j.ajax({
url: 'hooks/ajax_quote_subtotal.php',
data: {qid: qid},
success: function(data) {
$j('#LineItemsSubtotal').val(data);
$j('#Shipping').keyup();
}
});
} else {
$j('#LineItemsSubtotal').val('0');
$j('#Shipping').keyup();
}
};
这是与上面的ajax调用一起运行的ajax\u quote\u subtotal.php
:
<?php
$currDir = dirname(__FILE__) . '/..';
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
/* grant access to users with access to quotations table */
$od_from = get_sql_from('quotations');
if(!$od_from){
header('HTTP/1.0 401 Unauthorized');
echo "You do not have permission to access this page. If this behaviour is unexpected, please contact the system administrator";
exit;
}
$qid = intval($_REQUEST['qid']);
if(!qid) exit;
$parts_subtotal = sqlValue("select sum(Subtotal) from product_line_items where QuotationID='{$qid}' ");
$service_subtotal = sqlValue("select sum(Subtotal) from service_line_items where QuotationID='{$qid}' ");
$subtotal = $parts_subtotal + $service_subtotal;
sql("update quotations set LineItemsSubtotal='{$subtotal}' where QuotationID='{$qid}' ", $eo);
echo number_format($subtotal, 2);
?>
只要我不删除setTimeout
,这就行了,但是我觉得这不是一个好的解决方案。
如果删除了setTiemout
,则会创建记录,但它看起来像是在提交子记录之前运行函数,因此父记录中小计字段的值不包括最新添加的记录
我也试过:
if($j('input[name=Embedded]').val()==1){
$j('form').submit(function(e){
e.preventDefault();
this.submit();
window.parent.jQuery('.modal').modal('hide');
parent.update_lineitems_subtotal();
})
}
这在Chrome中也有类似的结果,甚至拒绝在Firefox中创建子记录
任何帮助都将不胜感激
另外,我对这一点还不熟悉,如果您有时间解释代码,您可能会建议,我们将不胜感激
if($j('input[name=Embedded]').val()==1){
$j('form').submit(function(e){
e.preventDefault();
this.submit();
window.parent.jQuery('.modal').modal('hide');
parent.update_lineitems_subtotal();
})
}