2011-04-30 66 views
0

我目前正在使用jqGrid php实现与手动事务在网格中添加记录。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(...)我猜)?

感谢,

回答

0

我不是PHP prorgammer,但我希望我可以帮助你。

首先,您在错误检测的情况下需要报告关于header PHP函数的错误HTTP status code。另外,您可以在响应正文中放置有关错误的信息(要显示的错误文本)。您可以选择任何格式的回复。

在客户端,您可以使用errorTextFormat事件句柄来解码和重新格式化服务器响应。您应该从errorTextFormat中返回想要在错误对话框中显示的文本或HTML碎片。

如果使用内联编辑,只需在服务器响应中放置要显示在错误对话框中的文本或使用errorfunc