I've got a wrapper function i use around the .getJSON method which
handles errors nicely

function reqJSON(url, params, success, error) {
    var CallParams = {};
    CallParams.type = params.Method || "POST";
    CallParams.url = url;
    CallParams.processData = true;
    CallParams.data = params;
    CallParams.dataType = "json";
    CallParams.success = success;
    if (error) {
        CallParams.error = error;
    }
    $.ajax(CallParams);
}


So instead of

$.getJSON(
     "location url",
     { Data to send },
     function(json) {
         // Handle result
     }
);

I call


reqJSON(
     "location url",
     { Data to send },
     function(json) {
         // Handle result
     },
     function(x,y,z) {
         //  x.responseText   holds the error message
     }
);


It's been working out great.....  i'll note too, that by default this
call to my function POST-s, not GET-s.....  just switch the ".type"
line to reflect if you would rather "GET"



On Jan 22, 4:35 am, ZNS <ulrik.anders...@gmail.com> wrote:
> Is this possible? I do not want to use the $.ajaxError event but
> catching the error directly like this:
>
> try
> {
> $.getJSON(.....);}
>
> catch (x)
> {
> alert("failed");
>
> }

Reply via email to