Fabii
Fabii

Reputation: 3890

Change ajax data on retry

Is there a way to change the supplied data on an ajax retry? I want to make the first call with user="auth" passed in the data params , if it fails then change the user to "ANON" and retry the call this new data param. The user shows up as undefined with the way I have it set up below.

     $.ajax({
            url : proxyurl,
            type : 'GET',
            dataType : 'xml',
            user : "auth",
            tryCount : 0,
            retryMax : 2,
            data : {'apireq': apiurl+"?user="+this.user},
            success : function(data){

            },
            error: function(xhr,textStatus,errorThrown){    
                   if (textStatus == 'parsererror') {
                       this.user = "ANON";
                       this.tryCount++;
                       if (this.tryCount <= this.retryMax) {
                           $.ajax(this)                                         //try the call again
                           return;
                       }            
                       return;
                   }
            }
     });

Upvotes: 0

Views: 129

Answers (1)

JCOC611
JCOC611

Reputation: 19729

We were able to reach the following solution:

error: function(xhr,textStatus,errorThrown){    
    if (textStatus == 'parsererror') {
        this.user = "ANON";
        this.data = {'apireq': apiurl + "?user=" + this.user };
        this.tryCount++;
        if(this.tryCount <= this.retryMax) {
            $.ajax(this); //try the call again
            return;
        }            
        return;
    }
}

Upvotes: 1

Related Questions