PHP:Ajax请求中找不到页面404

So, I'm sending a form with ajaxForm which will send data, open spinner.gif, then on success close spinner and reload the page:

$('#form').ajaxForm({
beforeSubmit:function(){
    spinnerLoad();},
success: function(data){
    spinnerDone();      
    window.location.href ="sample.php";
}
});

Then the form is handled like this:

if (isset($_POST['save'])){
  exec("/directory/script.php $args");
}

So this page, 'script.php' executes another script on DB, so it may take a long time. When there is not many data, it works fine, but whenever I have much, after a time 'script.php' wents 404, and the spinner.gif never stops.

I need to find a way to extend timeout somehow (ajax timeout option seems not suitable) or another way. Sending the script.php page or the DB script to background is not ok - it must be finished in order to continue working.

I'll be glad to any comments/directions to look.