【问题标题】:jqgrid php: how to report an error in dialogjqgrid php:如何在对话框中报告错误
【发布时间】:2011-04-30 22:19:27
【问题描述】:

我目前正在使用带有手动事务的 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(...))?

谢谢,

【问题讨论】:

    标签: jqgrid jqgrid-php


    【解决方案1】:

    我不是PHP程序员,但希望能帮到你。

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

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

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

    【讨论】:

      猜你喜欢
      • 2011-02-07
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多