title: Ajax GET method fails to load url, how to retry ajax until success?
body: <p>I am creating this simple weather app, where app gets weather data from openweathermap.org. From here I create url like this (where you get xml data):</p>
  
  <p><a href="http://api.openweathermap.org/data/2.5/forecast/weather?q=Koper,slovenia&amp;mode=xml&amp;units=metric" rel="nofollow">http://api.openweathermap.org/data/2.5/forecast/weather?q=Koper,slovenia&amp;mode=xml&amp;units=metric</a> </p>
  
  <p>So for my app, I am using jquery and this code for getting data from api:</p>
  
  <pre><code>$.ajax({
    type: 'GET',
    dataType: 'xml',
    url: "http://api.openweathermap.org/data...",
  }).done(function(data){
    xmlDoc = data;
  
    //from here I work with xml that I get, and put data into array to display chart
    var time=xmlDoc.getElementsByTagName('time');
    ...
  }).fail(function(){
    location.reload(); //this is not a good solution
  });
  </code></pre>
  
  <p>This works fine, <strong>but my problem is next:</strong> Sometimes the server from openweathermap does not response to my "url" call and get message error 404. Then If you refresh page (or url) several times, then it works. For temporary solution I add at "fail" function to reload page (location.reload). But this is not a good solution because, when server call fail, page is constantly reloading. </p>
  
  <p>Any idea how to fix this, when server fail to get data so it try to reconect again... tnx for help</p>