2011-03-07 97 views
0

我用这个Javascript代码线程标记为收藏:的.htaccess导致问题阿贾克斯

function fave(tid){ 
xmlhttp = createXHR(); 
if(xmlhttp){ 
    xmlhttp.onreadystatechange = function(){ 
    if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ 
    get("fave"+tid).innerHTML = xmlhttp.responseText; 
    } 
    } 
    xmlhttp.open("GET", "thread?act=fave&tid="+tid+"&ajax=1", true); 
    xmlhttp.send(null); 
} 
} 

我的.htaccess文件包含此行RewriteRule ^thread/([0-9]+)? /thread?tid=$1 [L],这更靓/thread/1234变成/thread?tid=1234

随着第一个网址一切正常,但/thread/1234会导致一个错误。 enter image description here 点击带下划线的链接回报: enter image description here

响应HTML是一整页的副本! 为什么只有/thread?tid=1234/thread/1234网址之间的唯一区别的文档具有不同的行为方式?

UPDATE:

RewriteRule ^thread/([0-9]+)? /thread?tid=$1 [L,QSA] 

改进的.htaccess线解决了这个问题。

+1

thread?act = fave&tid =“+ tid +”&ajax = 1与您的重写规则不完全匹配,所以我认为它没有被重写 – 2011-03-07 17:08:57

回答

4

尝试在你的htaccess中使用[QSA]修饰符。

第一次看,你的问题是重写URL后,ajax = 1和act = fave值不会被追加。

所以重写规则应该是:

RewriteRule ^thread/([0-9]+)? /thread?tid=$1 [L,QSA] 

然后你的代码:

xmlhttp.open("GET", "thread/"+tid+"?ajax=1&act=fave", true); 
+0

[ QSA]做到了真的有帮助。非常感谢! – 2011-03-07 17:14:37

0

必须有内捕捉PHP中的AJAX事件问题 - 尝试的var_dump的GET瓦尔...我认为你会错过“ajax标识符”:)