I have a page named A.aspx that loads a B.aspx using the load jQuery method. Like this:
$('#doclist').load('Documents.aspx #div1', { idMsg: $(this).data('cid') }, function (response, status, xhr) {
if (status == "error") {
var msg = "Error.";
$('#doclist').html("<span>" + msg + xhr.status + " " + xhr.statusText + ". " + "</span>");
}
});
This can handle exceptions such a 404 or 500 Internal server error. The B page retrieve data from DataBase and a DBException is thrown but not catched by load jQuery method.
I don’t do anything at code behind.
Response with
500 Internal server erroris the only thing script gets if there is no additional code o the server.Consider returning JSON with data you need instead of HTML page. This way you can have custom errors as alternative result. I.e. for success
{"result": ....}and in case of error:{"error":"Nice error explanation"}.