Daniel Harper
Daniel Harper

Reputation: 506

Force jQuery / Javascript to wait for php script to load

I'm having trouble making an ajax request wait for php script to load, the script works in chrome but not IE in both instances.

On a button press the script should fire a php script wait for it to complete then display an alert to say it has complete but in IE the alert box displays too quickly and the script never runs. It does work in chrome as expected.

This is attempt 1

 function reloadCalls(){
  $('#reload').prop('disabled', true);
  $('.ajax-progress-throbber').show();
  $.ajax({          
    url: '/kpi/technet_proj/cron/proj_cron.php',
     success: function(r){
       alert('Calls Loaded');       
       location.reload();
     },
     error: function(r){
       alert('Calls not loaded');
     }
  });
 }

This is attempt 2

 function reloadCalls(){
  $('#reload').prop('disabled', true);
  $('.ajax-progress-throbber').show();
  $.ajax({          
    url: '/kpi/technet_proj/cron/proj_cron.php',
     success: function(){
       alerts();
     },
     error: function(){
       alert('Calls not loaded');
     }
  });
}

function alerts(){
  alert('Calls Loaded');
  location.reload();
}

I have also tried adding async:false that does kind of work but it doesn't display the throbber and jams the browser until the script has complete.

Any help would be appreciated

Upvotes: 0

Views: 1136

Answers (1)

Daniel Harper
Daniel Harper

Reputation: 506

I worked it out the answer is to add cache: false to the ajax request.

Upvotes: 1

Related Questions