AJAX fetch API

by Sameer Shemna

HTML

<div id="main"></div>

JavaScript

$(document).ready(function(){
        callAjax();
        
      });
    var url = "https://www.toontownrewritten.com/api/invasions";
       function callAjax(){console.log('fired');
                           $('#main').html('');
            $.get(url,{},function(data){console.log('received');
        for(var index in data.invasions){
            var value = data.invasions[index];
                 
                  $('#main').append("<h3 style='text-align:center;margin:auto;'><b>District:</b> "+index+"</h3><br style='font-size:1px;'><h3 style='text-align:center;margin:auto;'><b>Cog:</b> "+value.type+"</h3><br style='font-size:1px;'><h3 style='text-align:center;margin:auto;'><b>Progress:</b> "+value.progress+"</h3>");
             }     
                setTimeout(callAjax,10000);
});
            
}