0

Am trying to get data from ajax if success data is empty need to call same ajax until ajax success data is returned.

Can some one help me to call ajax ever 2 sec until ajax returns data.

this.submitPax = function() {
   function getCityName() {
      var country = 1;
      //var ajaxUrl = "<?php echo WEB_URL_ADMIN; ?>checkdriverstatus";

      tjq.ajax({
         url: baseUrlIs + "checkdriverstatus",
         dataType: 'json',
         type: 'post',
         data: { "countryID": country },
         success: function(response, textStatus, request) {
            //alert(response);
            if (response != '') {
               tjq("div#divLoadingSeat").removeClass('show');
            } else {
               alert('Waiting for driver to accept job');
               //setTimeout(function(){getCityName();}, 1000);
               tjq("div#divLoadingSeat").addClass('show');
               return false;
            }
         },
      });
   }
}
Zuckerberg
  • 1,781
  • 2
  • 10
  • 19
satish k
  • 37
  • 7
  • 3
    Does this answer your question? [What's the best way to retry an AJAX request on failure using jQuery?](https://stackoverflow.com/questions/10024469/whats-the-best-way-to-retry-an-ajax-request-on-failure-using-jquery) – Mukund Goel Apr 15 '20 at 07:14
  • Thanks @MukundGoel. Am getting success on every ajax call some times success returns empty data. when empty data received need to call same ajax – satish k Apr 15 '20 at 07:17
  • Have you considered using Websockets instead of Ajax polling? By doing so, the server can actively send data when there actually *is* new data. This also saves a lot of overhead data which might be desirable on mobile devices. – Rob Apr 15 '20 at 07:26
  • Thanks @Alex need to use Ajax only at this time – satish k Apr 15 '20 at 07:29

0 Answers0