通过Ajax请求文件

时间:2016-02-25 04:35:54

标签: javascript php ajax setinterval

我已经尝试过这个作为上一个问题的答案,但它不起作用它只报告500内部服务器错误和Firebug没有报告错误的任何细节:

(function worker() {
$.ajax({
   url: 'buildmarkers.inc.php',
   type: 'POST', 
   success: function(data) {
$('.result').html(data);
},
complete: function() {
   // Schedule the next request when the current one's complete
setTimeout(worker, 30000);
}
});
})();

当我这样尝试时,它正在运作:

<?php include('buildmarkers.inc.php')?>

2 个答案:

答案 0 :(得分:0)

你真正的问题是,&#34;为什么我会收到500错误。&#34;如果没有buildmarkers.inc.php的代码,就无法确定答案。你没有在firebug中看到任何东西,因为它是服务器端错误。如果您修改了javascript并添加了错误功能,那么您将在客户端上看到它失败。

(function worker() {
$.ajax({
   url: 'buildmarkers.inc.php',
   type: 'POST', 
   success: function(data) {
     $('.result').html(data);
   },
   error: function(data){
     console.log("Save me Tom Cruise! The server is on fire!");
   },
   complete: function() {
     // Schedule the next request when the current one's complete
     setTimeout(worker, 30000);
   }
  });
})();

答案 1 :(得分:0)

Ajax调用将获取具有URI相对路径的文件(基于DOCUMENT_ROOT或webserver),它可能与使用当前脚本文件的绝对路径的PHP中的include()不同。你可以:

  1. 检查项目的文件夹结构,您的脚本路径和&#34; buildmarkers.inc.php&#34;之间是否存在差异?
  2. 您的网络服务器是否有任何重写规则?
  3. 您应该检查网络服务器的错误日志,它应该显示有用的消息。