我目前正在使用带有手动事务的 jqGrid php 实现来在网格中添加记录。
例如:
$oper = jqGridUtils::GetParam('oper');
if ($oper == 'add') {
$grid->trans = false; // disable the transaction
try {
jqGridDB::beginTransaction($conn);
$reference = jqGridUtils::GetParam('reference');
$name = jqGridUtils::GetParam('name');
$brand = jqGridUtils::GetParam('brand');
$price = jqGridUtils::GetParam('price');
$total_quantity_left = jqGridUtils::GetParam('total_quantity_left');
$product = jqGridDB::prepare($conn,
"INSERT INTO product (id, reference, name, brand, price, total_quantity_left) VALUES (NULL,?,?,?,?,?)",
array($reference,
$name,
$brand,
$price,
$total_quantity_left,
)
);
$stock1 = jqGridDB::prepare($conn,
"INSERT INTO stock (id, shop_id, product_id, quantity) SELECT NULL, 1, (SELECT MAX(id) FROM product), ?",
array(jqGridUtils::GetParam('quantity_shop1'))
);
$stock2 = jqGridDB::prepare($conn,
"INSERT INTO stock (id, shop_id, product_id, quantity) SELECT NULL, 2, (SELECT MAX(id) FROM product), ?",
array(jqGridUtils::GetParam('quantity_shop2'))
);
jqGridDB::execute($product);
jqGridDB::execute($stock1);
jqGridDB::execute($stock2);
jqGridDB::commit($conn);
} catch(Exception $e) {
jqGridDB::rollBack($conn);
echo $e->getMessage();
}
}
到目前为止,这工作正常。
我现在遇到的问题是,如果交易过程中发生错误,我想通知用户:通常我想弹出一个错误对话框,显示 $e->getMessage() 或错误原因。
由于在 php 级别检测到错误,我如何调用 javascript 代码部分来实现这一点(我猜是alert(...) 或 $.jqgrid.info_dialog(...))?
谢谢,