Wednesday, February 15, 2012

jqGrid - php throw custom server error/exception and work with loaderror

If you want to throw a custom error/ exception in the server side script, php, and return to the jqGrid to capture your custom error code and error message, I hope my example here can help you.

After reading some threads and testing, it's actually quite simple and only need to throw an appropriate header in PHP, and then quit your script.

php:
header('HTTP/1.0 500 My custom error');

you can throw other status code but other than 2xx which represents a successful return. Also, you can see the reference here, Hypertext Transfer Protocol -- HTTP/1.1

javascript:
In the loadError event of jqGrid, you can get the status code and the message you return:

loadError : function(xhr,status,error) {
        alert(xhr.status+','+status+','+error); 
//alert 500, error, My custom error
},


No comments: