I’m using Jquery, and I’m very happy with that !

for a project where are reading some data using Json format, but in the Json call I was missing how to handle possible errors, this is the fragment of jquery code that I’m using to read the json data

    $(“#message”).html(“searching”);

var criteria = $(“#criteria”).val();
var index = $(“#index”).val();
var limit = $(“#limit”).val();
var url = “search.html?index=” + index + “&criteria=” + criteria + “&limit=” + limit;

$.getJSON(url,
function(data){
$(“#message”).html( data.length + ” records found”);
var html = eval( index + “Result(data)”);
$(“#result tbody”).html(html);
});

and this finally is the code that I’m using to handle the errors

$(“#message”).ajaxError( function(event, request, settings){
$(this).append(“<b>Error requesting page ” + settings.url + “</b>” );
$(this).append(“<br/>” );
$(this).append(“error details<br/>” );

jQuery.each(settings, function(i,val) {
$(this).append(i + ‘=’ + this + “<br/>”);
});
}
);

of course could be more nice like hidden details, and press something to show the details, but this is another post … =)