App.request what is the best way to retry an AJAX request using app.request?

I do not know if there is an issue for this but I wonder if there is a way to do Ajax retries after a timeout so if the server reply is not ok because it cannot return information at that time then I do a retry of the Ajax call and the dialog close and open automatically searching again for a second, third retry… to get finally the response…

I have tried to use:

retry: 5
timeout: 5000

but it is not working when using app.request…

any information regarding what is the best way to retry an AJAX request using app.request?
thanks

This should help. It looks pretty straight forward if you know Javascript…

Look at Sudhir Bastakoti’s answer…

Just tried it out…actually… Works like charm… Kindly mark this as solved if it helps you… Many of us are always looking out for solved issues…to avoid time wasted while waiting…

                            app.request({
                                url: 'API_ENDPOINT',
                                dataType: 'json',
                                method: 'GET',
                                cache: false,
                                tryCount : 0,//starting request,,,
                                retryLimit : 3,//no of retries...
                                timeout: 1000,//must set so it doesnt request forever, between trials...
                                data: {
                                   data : anything,
                                },
                                crossDomain: true,
                                success: function (data) {
                                          console.log(data);
                                    },
                                    error : function(xhr, textStatus, errorThrown ) {

                                            if (textStatus == 'timeout') {
                                                this.tryCount++;
                                                if (this.tryCount <= this.retryLimit) {
                                                    //try again
                                                   app.request(this);
                                                     //check if it retried by checking the response...
                                                    console.log(this.tryCount);
                                                   
                                                    return;
                                                }            
                                                return;
                                            }
                                  }
                              });
2 Likes

thank I will try this way and let you know if it works as it should :slight_smile: thanks for the tips