我想问的是我有一个jqgrid列表,我想在屏幕上收到错误消息,以防删除失败。这是我的代码:
<html>
<body>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
jQuery("#list").jqGrid({
url:'../listeAjax',
datatype: "json",
colNames:['Id','Hizmet adı', 'Sektörler', 'Durum', 'Düzenle'],
colModel:[
{name:'onto_data_id',index:'onto_data_id', width:55, editable: false},
{name:'baslik',index:'baslik', editable:true, editrules:{required:true}, formoptions:{ elmprefix:"(*)"}},
{name:'sektor_list',index:'sektor_list', editable:false},
{name:'is_active',index:'is_active', align: 'center', editable:true, stype:'select',
editoptions:{value:":All;1:<?php echo lang('title_aktif')?>;0:<?php echo lang('title_pasif')?>", defaultValue:1},
edittype:"select"
},
{name:'duzenle',index:'duzenle', align: 'center', sortable:false, search: false, editable:false}
],
rowNum: <?php echo DEFAULT_GRID_ROWNUM; ?>,
rowList:[100,200,400,800],
pager: '#pager',
sortname: 'onto_data_id',
viewrecords: true,
sortorder: "desc",
multiselect: true,
width: 800,
height: "100%",
editurl: '../islemAjax',
caption: "Hizmetler",
mtype: "GET",
postData:{parent_id: '<?php echo $parent_id; ?>', parent_type: '<?php echo $parent_type; ?>'}
});
jQuery("#list").jqGrid('navGrid','#pager',
{edit:true, add:true, del:true, search:false},
{closeOnEscape:true, bottominfo:"<?php langValue('info_yildizlialanlar'); ?>",editData: {
parent_id: function() {
return '<?php echo $parent_id; ?>';
},
parent_type: function() {
return '<?php echo $parent_type; ?>';
},
tur: function() {
return '<?php echo ONTO_TYPE_HIZMET; ?>';
}
}},
{
beforeSubmit: function(postdata, formid){
var message;
$.ajax( {
type : 'POST',
dataType : 'json',
url : "<?php echo URL_YONETIMDATACONTROL; ?>",
data : 'baslik='+postdata.baslik + '&parent_id=' + <?php echo $parent_id; ?> + '&parent_type=' + <?php echo $parent_type; ?> + '&onto_type=' + <?php echo ONTO_TYPE_HIZMET ; ?>,
async : false,
success : function(result) {
if(result.status == true) {
complete = true;
} else {
complete = false;
}
message = result.message;
},
error: function (data, status, e) {
complete = false;
message = e;
}
});
return [complete, message, ""];
},
closeOnEscape:true, bottominfo:"<?php langValue('info_yildizlialanlar'); ?>",editData: {
parent_id: function() {
return '<?php echo $parent_id; ?>';
},
parent_type: function() {
return '<?php echo $parent_type; ?>';
},
tur: function() {
return '<?php echo ONTO_TYPE_HIZMET; ?>';
}
}},
{delData: {
parent_id: function() {
return '<?php echo $parent_id; ?>';
},
parent_type: function() {
return '<?php echo $parent_type; ?>';
}
}},
{}
);
jQuery("#list").jqGrid('filterToolbar');
} );
</script>
<h1>
<?php echo langValue('title_hizmetliste'); ?>
<?php
if(isset($sektor_baslik))
{
echo '(' . $sektor_baslik . ')';
}
?>
<a href="<?php echo URL_YONETIMHIZMETEKLE; ?>" title="<?php echo langValue('form_ekle')?>" class="tooltip">
<img src="<?php echo PATH_MEDIA_IMG_YONETIM; ?>icons/8_48x48.png" alt="" />
</a>
</h1>
<div class="pad20">
<?php if(isset($info)) { ?>
<div class="message success close">
<h2><?php echo $info; ?></h2>
</div>
<?php } ?>
<!-- Tabs -->
<div id="tabs">
<!-- First tab -->
<div id="tabs-1">
<table id="list"></table>
<div id="pager"></div>
</div>
</div>
</div>
</body>
</html>
我插入了AfterSubmit但它什么也没有返回。而且,当我在afterSubmit中提醒文本时,没有任何反应。这是我尝试的后续提交代码:
afterSubmit : function(response, postdata)
{
alert("test");
return [success,message,new_id]
}
这里有什么问题?
答案 0 :(得分:1)
服务器响应的错误处理主要有两种情况:1)响应包含一些错误的HTTP代码; 2)响应包含一些成功的HTTP代码。如果响应成功(从HTTP代码的角度来看),将执行回调afterSubmit
。如果出现错误响应(从HTTP代码的角度来看),将执行回调errorTextFormat
。所以你需要使用像
{
delData: {
parent_id: function() {
return '<?php echo $parent_id; ?>';
},
parent_type: function() {
return '<?php echo $parent_type; ?>';
}
},
errorTextFormat: function (jqXHR) {
alert(jqXHR.responseText);
return "Error code: " + data.status + ", Description: " + jqXHR.responseText;
}
}
errorTextFormat
的确切代码取决于出现错误时jqXHR.responseText
的内容。在许多情况下,最好只使用jqXHR.responseText
的子集来获得最可读的结果。请参阅the answer。
我建议您不仅要测试代码明确生成错误响应的情况,还要测试另外两种情况:1)常见服务器错误(例如,如果您使用不存在的{{1} } for delete operation)2)客户端错误,如来自服务器的超时。