如何从 PHP 创建 jqGrid JSON 错误响应,然后使用 jqGrid javascript 响应它?
我一直在搜索互联网和 jqGrid 文档,但我找不到任何有关创建、更新、删除 (CRUD) 操作的 JSON 响应格式的信息。当然应该有一个从 PHP 返回到 jqGrid 的 JSON 消息来告诉它 CRUD 操作是否成功?该消息的格式是什么?您将如何编写 jqGrid 的 javascript 来响应该消息?我不是一个很好的程序员,所以完整的代码答案将不胜感激。
谢谢
I have been searching the internet and the jqGrid documentation, but I can't find anything about the format of a JSON response to a create, update, delete (CRUD) operation. Surely there should be a JSON message that is returned from PHP to jqGrid to tell it whether the CRUD operation was successfull? What is the format of this message and how would you code the javascript for the jqGrid to respond to that message? I'm not a very good programmer, so complete code answers would be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要使用响应来创建、删除和更新。
例如,如果您执行创建操作,您将调用“ajax 操作”,它将您的数据添加到数据库中。
现在有两种可能性:
如果 jqGrid 收到非 200 响应代码,它本身会向您显示错误!
对代码感到抱歉,但这是我现在脑子里最快的:)
我将 jqGrid 与 Zend Framework 结合使用,ZF 默认使用 500 个异常响应代码(至少是我的模板)。
成功更新/删除/创建后,您必须重新获取整个 jqGrid 数据。
据我所知没有其他机制。 (大约 6 个月前使用过它,也许情况发生了变化)
如果您想实现自己的错误/成功处理,只需以您想要的任何格式定义您自己的消息,并在 ajax 成功函数回调中处理它。
如果您需要更多代码并且不紧急,请给我留言。
另一条建议:不要指望立即理解 jqGrid。花点时间,尝试一些事情,玩玩它。您需要一段时间才能适应它。
You don't need to use a response for create, delete and update.
E.g. if you do an create operation you are calling an "ajax operation" which adds your data into a database.
There are now two possibilites:
If jqGrid receives an non 200 response code it shows you an error itself!
Sorry for the code, but it was the fastest I get out of my brain now :)
I use jqGrid in combination with the Zend Framework and ZF uses 500 Response codes for Exceptions by default (at least my template)
After a successful update/delete/create you have to refetch the whole jqGrid data.
There is afaik no other mechanism. (Used it last about 6 months ago, maybe that changed)
If you want to implement your own error/success handling, just define your own message in whatever format you want and handle it in the ajax success function callback.
If you need more code and it is not urgent, just drop me a comment.
One additional advice: Don't expect to understand jqGrid immediatly. Take your time, try some things, play with it. It will take some time before you feeling comfortable with it.