Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Extend jQuery ajax function to retry requests and perform compensate action

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 index.htm
Octocat-spinner-32 jquery-1.8.2.js
Octocat-spinner-32 readme.md
Octocat-spinner-32 retryAjax.js
Octocat-spinner-32 test.html
readme.md

retryAjax

I wanted a little wrapper function to retry ajax requests in the event of transient failures (particularly likely for mobile sites). This is my first stab at a little wrapper over jQuery's ajax function.

Options:

  • retries: The number of times to retry requests (default is 3)
  • backoff: Boolean option on whether to increase time between attempts (default false)
  • backoffInterval: Starting interval between wait time for requests (default 1000),
  • backOffFunc: Function to increase time between retries (default function multiples current backoffInterval value by 2 on each attempt)

Example usage:

$.ajaxWithRetries(
    {
        url: "badUrl.html",  
        error: function(){
            console.log('original error handler func');
        } 
    },
    {
        retries: 3,
        backoff: true
    }
);

Something went wrong with that request. Please try again.