How can I get JQGrid to recognize server sent Errors?

后端 未结 8 1079
清酒与你
清酒与你 2020-12-09 16:42

I have a jqgrid that\'s functionning very well.

I was wondering is it possible to catch server sent errors ? how Is it done ?

8条回答
  •  鱼传尺愫
    2020-12-09 17:01

    From what I see, it returns the data as a json string. So what you have to do is add an error handler that formats the error as a json string and prints it out as one. This can be done in php with the

    set_error_handler
    

    function.

    The error handler would then I guess push the data in to jsonReturn.error, so you would just need to check for that when you are adding your data to the table.

    If you are throwing exceptions instead of letting it get all the way to errors (probably a better practice), then you would want to format the exception as a json string.

    Since it is returning the data in an xml format, you would want to parse the xml:

    
        
            error message
        
    
    

    like this:

    $(request.responseXML).find("error").each(function() {
            var error = $(this);
            //do something with the error
    });
    

    Shamelessly borrowed from: http://marcgrabanski.com/article/jquery-makes-parsing-xml-easy

提交回复
热议问题