开发者

.htaccess Causes Problem With Ajax

I use this Javascript code to mark threads as favourite:

function fave(tid){
 xmlhttp = createXHR();
 if(xmlhttp){
  xmlhtt开发者_JS百科p.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);
 }
}

My .htaccess file contains this line RewriteRule ^thread/([0-9]+)? /thread?tid=$1 [L], which turns /thread?tid=1234 in more pretty /thread/1234.

With the first URL everything works fine, but /thread/1234 causes an error.

.htaccess Causes Problem With Ajax

Click on the underlined link returns:

.htaccess Causes Problem With Ajax

Response HTML is a copy of a whole page! Why the same document with the only difference between /thread?tid=1234 and /thread/1234 URLs behaves in different ways?

UPDATE:

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

The improved .htaccess line solved the problem.


Try using the [QSA] modifier in your htaccess.

At the first look, your problem is that the ajax=1 and act=fave values do not get appended after rewriting the URL.

So the RewriteRule should be:

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

And then your code:

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


There must be problem within capturing the AJAX event in PHP - try to var_dump the GET vars ... I think that you will miss "the ajax identifier" :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜