The solution is to keep count of the number of times the function is called to execute AJAX request and on failed requests recall the function. The retryLimit can be modified to the number to times the AJAX function is called.

function callback(){
            tryCount : 0,
            retryLimit : 3,
            $.ajax({
            ....
             ....
            error: function(x, t, m) {
                if(t==="timeout" || x.statusText == "error") {
                    this.tryCount++;
                    if(this.tryCount <= this.retryLimit)
                        callback();
                }
            }
       });
}