我用这个函数删除行:
- function deleteRow(){
- rows = jQuery("#category_grid").getGridParam('selarrrow');
- if( rows.length>0){
- jQuery('#category_grid').delGridRow(rows,{
- msg:'Verwijderen geselecteerde rijen?'
- });
- }else{
- alert("Selecteer eerst een rij om te verwijderen!");
- }
- }
但是当它在我的PHP中失败时,服务器端会抛出异常.错误消息看起来不太好.如何在对话框中显示errotext?或者在ajax调用后收到错误消息?
目前错误消息如下所示:错误状态:’CDbException’.错误代码:500
当我用Google搜索时,我发现了一个名为errorTextFormat的delGridRow函数.这是我要找的活动吗?有人可以举个例子说明这次活动的实施情况吗?
问候
尼尔斯
delGridRow的第二个参数是带有选项的对象,因此您可以执行以下操作
- jQuery('#category_grid').delGridRow(rows,{
- errorTextFormat: function (data) {
- if (data.responseText.substr(0,6) == "<html ") {
- return jQuery(data.responseText).html();
- }
- else {
- return data.responseText;
- // or
- // return "Status: '" + data.statusText + "'. Error code: " +data.status;
- }
- }
- });
您通过errorTextFormat函数返回的文本retText将放置在delGridRow函数内的jQuery.html(retText)代码的错误消息的相应div中.
顺便说一句,我不直接调用delGridRow函数.而不是如果我将导航栏添加到jgGrid关于navGrid函数,我将errorTextFormat函数作为参数提供给标准的“删除按钮”.确切地说,我是关于$.jgrid.del这样做的:
- jQuery.extend(jQuery.jgrid.del,{
- ajaxDelOptions: { contentType: "application/json" },mtype: "DELETE",reloadAfterSubmit: false,jqModal: false,serializeDelData: function (postdata) {
- return "";
- },errorTextFormat: function (data) {
- if (data.responseText.substr(0,6) == "<html ") {
- return jQuery(data.responseText).html();
- }
- else {
- return "Status: '" + data.statusText + "'. Error code: " + data.status;
- }
- }
- });
(我的errorTextFormat的真实代码看起来有点复杂,但使用的想法是一样的).