Jqgrid显示json中的错误



我的问题是这样的,我想通过我得到json的信息显示错误。也就是说,当我们在jgrid中添加/编辑某些内容时,我们总是希望得到json数据中的响应。然后我想起来是什么,如果你不能添加一些东西,我就发送json错误。

我想在Jquery中使用Highlight/error来显示错误。这就是我的问题所在,我该如何表现。从我一直在搜索,应该是属性后提交实现和处理这里的响应,但只是我没有得到。

代码:

afterSubmit: function (response) 
{
   if(responce == false)
        alert("test");
}

json格式错误:

{"Response":false,"Message":"Dados inválidos"}

有人能帮帮我吗?

---------------------------------------- <</strong strong>解决方案> ------------------------------------------------------

jQuery.extend(jQuery.jgrid.edit, 
    {
        reloadAfterSubmit:false,
        afterSubmit: function (response, postdata) 
        {
            if(jQuery.parseJSON(response.responseText).Response  == false)
            {
                alert(jQuery.parseJSON(response.responseText).Message);
                return [false,null,null];
            }
            else
            {
                return [true,null,null];
            }
        }
    }); 

试试这个

afterSubmit: function (response, postdata) 
{
  if(jQuery.parseJSON(response.responseText).Response)
alert(jQuery.parseJSON(response.responseText).Message);
}

我认为对于错误,只需从AJAX脚本返回错误作为字符串。JqGrid期望获得JSON数据,但是当它接收到字符串时,它将为您显示错误。

我使用JqGrid的XML而不是JSON,但在我的AJAX脚本中,当我有一个错误,我只是返回一个字符串,而不是JqGrid期望的XML,网格正确显示错误消息。

请在提交代码后尝试此操作,看看是否有任何结果:

afterSubmit: function (response) 
{
   alert(response);
}

如果你能看到这个,那么你就已经设置好了,你只需要调整这个函数,使它只在实际出现错误时显示响应。

最新更新