我最近将我的 XAMPP 从 1.8.1 升级到 1.8.3,其中包括将 php 从 5.4 升级到 5.5,以及将 mySQL 从 5.5 升级到 5.6。
升级后,我的 ajax 轮询脚本不起作用我的代码如下:
  //define setInterval in global variable, to be cleared later      
  myInterval = setInterval(function(){ 
     //this alert works
     alert('inside interval');
     $.ajax({
           url: "../php/pollScript.php",
           dataType: "json",
           data: {action: 'get_count' },
           success: function(data){
               //never reaches this function, alert is not seen
               alert('success');
           },
           error: function (xhr, ajaxOptions, thrownError) {
               alert(xhr.status);
               alert(thrownError);
           }
     )};
  }, 2000);
 //use jquery ajax form to submit form that invokes long running php script
 $("form").submit();
 //interval is cleared in success function of ajax form submit
很明显, setInterval 函数正在工作,但是 ajax 函数没有被执行,我确保使用session_write_close();在释放会话的长时间运行脚本中,更新前没有更改任何代码。对正在发生的事情有任何想法吗?我需要在php.ini中更改配置以允许轮询吗?
更新:添加错误处理程序后,我的错误状态为 0,想不出为什么会发生这种情况,因为我没有更改任何代码,我读到这可能是您的 ajax 请求在完成之前被取消的结果......还有chrome dev tools->Networking 选项卡中的 pollingScript.php 在服务器上没有命中
长时间运行的脚本也可以完美运行。