3
votes

I use jQuery 1.2.6 (legacy).

In my general configuration I have set these options:

jQuery(document).ajaxStart(blockUI).ajaxStop(jQuery.unblockUI);

I have an ajax function that gets a javascript file:

function initWebtrends() {
    console.debug("initWebtrends start");       

    var options = {
        url : "ajax/myjavascript.js",
        success: function(data) {                   
            console.debug("webtrends integration successfully done...");
        },
        error:function(msg) {
            console.debug("error contacting webtrends client component...");                
        }
    };

    jQuery.ajax(options);

    console.debug("initWebtrends stop");
}   

All works great when the ajax get response correctly: the ajaxStart and the ajaxStop events are triggered. But when I got a 404 error the error callback function is not called neither the ajaxStop event: in this case I do not receive any error but my page remains freeze since the ajaxStart is triggered and the blockUI function is executed.

Is there a way to handle this kind of situation? I know that on jquery 1.5 there's the statusCode option, but I have to make it work on my legacy version.

Kind regards

Massimo

1
in your version is it possible to use success:,error: function - Sam Arul Raj T
This is true, but the error function is not called with a 404 error as described here forum.jquery.com/topic/… - Massimo Ugues

1 Answers

2
votes

as pointed out in the comments by @Massimo Ugues: statuscode is not present in jQuery 1.2.6. It's present on jquery >1.5


use the statusCode (present in jquery 1.5+)

$.ajax({
  statusCode: {
    404: function() {
      alert('page not found');
    }
  }
});

also you can take the statusCode to the ajaxSetup

 $.ajaxSetup({
  statusCode: {
        404: function() {
          alert('page not found');
        }
      }    
   });