Ajax async true gets timeout issues

I am using django, nodejs, ajax request.

In Django I am using requests library for sending the REST request to Node.js

I am getting timeout issues and some times web page got broken when using async true in ajax request.

I had given simple example as follows

The concept is I have variable called arr = ["INDIA", "USA","UK","CANADA"]

AJAX —–Request—–> DJANGO ——-Request——-> NODEJS
(Giving each country information)

AJAX <——–Response——- DJANGO <——–Response——- NODEJS

   $(function() {
      $.each(arr, function( key, value ) {
        $.ajax({
            type: "POST",
            url: "/country/",
            data:{country:value},
            dataType : 'html',
            cache: false,
            timeout: 10000000,            
            async: true,
            success:function(data){
              $('.country').empty();
              $('.country').html(data);        
            },
          error: function(jqXHR, textStatus, errorThrown) { 
              console.log("ERROR: " + textStatus);
          }
          });    
        });
    });

CURRENT OUTPUT:

INDIA is incredible
USA is happy country
ERROR: timeout
ERROR: timeout

DESIRED OUTPUT:

INDIA is incredible
USA is happy country
UK is cool contry
CANANDA is secure country


Source: ajax

Leave a Reply