I'm currently using the jqGrid php implementation with a manual transaction for adding a record in the grid.
E.g.:
$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');
$bran开发者_开发百科d = 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();
}
}
This works fine so far.
The problem that I have now is that I want to inform the user if an error occurred during the transaction: typically I'd like to popup an error dialog showing the $e->getMessage(), or the cause of the error.
Since the error is detected at the php level, how do I invoke a javascript code portion to achieve this (alert(…) or $.jqgrid.info_dialog(…) I guess)?
Thanks,
I am not PHP prorgammer, but I hope I can help you.
First what you need in case of error detection is to report an error HTTP status code with respect of header PHP function. Additionally you can place the information about the error (the error text to display) in the response body. You can choose any format of the response.
On the client side you can use errorTextFormat event handle to decode and reformat the server response. You should just return from the errorTextFormat the text or HTML fragmant which you want to display in the error dialog.
In case of the usage of inline editing you should just place in the server response the text which you want to display in the error dialog or use errorfunc.
精彩评论