jqgrid php:如何在对话框中报告错误

发布于 2024-11-04 04:16:48 字数 2151 浏览 1 评论 0原文

我目前正在使用 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(…) 我猜)?

谢谢,

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');
        $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();
    }
}

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-11-11 04:16:48

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

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文