通过 Ajax 请求文件
Requesting a file through Ajax
我已经尝试将此作为我上一个问题的答案,但它不起作用,它只报告 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')?>
您真正的问题是,"Why am I getting a 500 error.",如果没有 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);
}
});
})();
Ajax 调用将获取 URI 相对路径的文件(基于 DOCUMENT_ROOT 或网络服务器),它可能与使用绝对路径的 PHP 中的 include() 不同当前脚本文件。你可能:
- 检查你项目的文件夹结构,你的脚本路径和"buildmarkers.inc.php"的有什么不同吗?
- 它在你的网络服务器上有任何重写规则吗?
- 您应该检查网络服务器的错误日志,它应该会显示有用的消息。
我已经尝试将此作为我上一个问题的答案,但它不起作用,它只报告 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')?>
您真正的问题是,"Why am I getting a 500 error.",如果没有 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);
}
});
})();
Ajax 调用将获取 URI 相对路径的文件(基于 DOCUMENT_ROOT 或网络服务器),它可能与使用绝对路径的 PHP 中的 include() 不同当前脚本文件。你可能:
- 检查你项目的文件夹结构,你的脚本路径和"buildmarkers.inc.php"的有什么不同吗?
- 它在你的网络服务器上有任何重写规则吗?
- 您应该检查网络服务器的错误日志,它应该会显示有用的消息。