在ajax请求jqgrid后出现错误时显示漂亮的错误消息 [英] Display nice error message when there is something wrong after ajax request jqgrid
问题描述
我使用此函数删除行:
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,服务器端和抛出异常。 errormessage看起来不好。如何在对话框中显示错误?或者在ajax调用之后捕获错误消息?
but when it's fails in my php, server side and a exception is thrown. The errormessage looks not nice. How can i show errotext in the dialog box? or catch an error message after an ajax call?
此时错误消息如下所示:error Status:'CDbException'。错误代码:500
At the moment the error message looks like: error Status: 'CDbException'. Error code: 500
当我googled我发现一个delGridRow函数的事件,称为errorTextFormat。这是我在寻找的事件?
When i googled i found a event of the delGridRow function called errorTextFormat. Is this the event where i'm looking for? Can someone please give me an example of the implementation of this event?
niels
推荐答案
delGridRow
的第二个参数是一个带有选项的对象,
The second parameter of delGridRow
is an object with options, so you can do like following
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;
}
}
});
文本 retText
通过 errorTextFormat
函数将被放置在相应的 div
错误消息相对于 jQuery 。 c>
The text retText
, which you give back by errorTextFormat
function will be placed in the corresponding div
of the error message with respect of jQuery.html(retText)
code inside of delGridRow
function.
顺便说一句,不要直接调用 delGridRow
函数。而不是如果我添加导航栏到jqGrid关于 navGrid
函数,我给我的 errorTextFormat
函数为标准删除按钮的参数。确切地说,我对 $。jgrid.del
:
By the way I don't call delGridRow
function directly. Instead of that if I add the navigation bar to the jqGrid with respect of navGrid
function, I gives my errorTextFormat
function as a parameter to standard "Delete button". To be exact I do this with respect of $.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
喜欢有点复杂,但使用的想法是一样的)。
(the real code of my errorTextFormat
looks like a little more complex, but the idea of usage is the same).
这篇关于在ajax请求jqgrid后出现错误时显示漂亮的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!