byCoder
byCoder

Reputation: 9184

Jquery ajax if error do one more time this request

I have such code to get some data via ajax, but sometime's it can raise error...

$.ajax({ 
      url: "/carts/get_cart_totalqnt/qnt/cart/", 
      type: "GET", 
      data: {id: $(".cartid").attr("id")},
      success: function(text)
      {
        $("#total_count").html(text + " товар(ов)");
      },
      error: function(){
        alert('Ошибка javascript');
      },
      dataType : "html"
    });  

But how can i do, that if i get error i do one more time this request?

Just if error, do this ajax request one more time

Upvotes: 0

Views: 104

Answers (1)

cetver
cetver

Reputation: 11829

var retries = 3;    

error: function(jqXHR, textStatus, errorThrown) {
    if (textStatus == 'Internal Server Error') {
        do {
            $.ajax(this);
            retries--;
        } while (retries < 1)
    }
}

possible values of textStatus you can find here

Upvotes: 1

Related Questions