【发布时间】:2015-11-27 14:25:58
【问题描述】:
好的,我不知道如何提出这个问题,但我试图让它简短易懂。
所以我一直在关注this 教程。 (完整代码)
我根据自己的喜好稍微修改了代码,但出现此错误
GET http://sample.com/refresh.php/?lastTimeID=0 404 (Not Found)
(来自浏览器开发者控制台)
我认为这是出错的代码..
var lastTimeID = 0;
$(document).ready(function() {
$('#btnSend').click( function() {
sendChatText();
$('#chatInput').val("");
});
startChat();
});
function startChat(){
setInterval( function() { getChatText(); }, 2000);
}
function getChatText() {
$.ajax({
type: "GET",
url: "/refresh.php?lastTimeID=" + lastTimeID
}).done( function( data )
{
var jsonData = JSON.parse(data);
var jsonLength = jsonData.results.length;
var html = "";
for (var i = 0; i < jsonLength; i++) {
var result = jsonData.results[i];
html += '<div>(' + result.chattime + ') <b>' + result.usrname +'</b>: ' + result.chattext + '</div>';
lastTimeID = result.id;
}
$('#view_ajax').append(html);
});
}
function sendChatText(){
var chatInput = $('#chatInput').val();
if(chatInput != ""){
$.ajax({
type: "GET",
url: "/submit.php?chattext=" + encodeURIComponent( chatInput )
});
}
}
这就是我感到困惑的地方;它显示http://sample.com/refresh.php/?lastTimeID=0
但是在 refresh.php 之后它在哪里得到“/”?这应该发生吗?与.htaccess 有什么关系?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /admin/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /admin/index.php/$1 [L]
如何解决此错误?
就像我说的,我不知道如何正确地问这个问题。
还有一个小问题;查看浏览器开发者控制台是否合适?
如果您需要更多信息,请随时询问!
提前致谢。
【问题讨论】:
-
你有配置htaccess吗?它的内容是什么?
-
404 失败与变量 pass(?lastTimeID=0) 无关。如果它也产生404错误,你是否尝试直接从url栏加载sample.com/refresh.php/?lastTimeID=0。如果已安装,还可以共享 .htaccess 代码
-
@YPS 感谢您的快速响应。如果我加载 sample.com/refresh.php/?lastTimeID=0 它给了我一个 404 错误。我将添加 .htaccess
-
我猜你的 htaccess 确实搞砸了,刚才(chrome)我在控制台中写了
$.ajax({type: "GET", url: "/refresh.php?lastTimeID=2"}).done(function(){ console.log(arguments);});,它给了我“GET stackoverflow.com/refresh.php?lastTimeID=2&_=1441180776327 404(未找到)”;)试试一条一条地注释掉规则..? -
GET http://sample.com/refresh.php?lastTimeID=0refresh.php 后删除 \