2014-03-03 82 views
0

我的問題是此代碼:xmlhttp.open("GET","oy.php?antivirus="+y,true);.htaccess文件不允許ajax獲取命令?

y是0無論我做什麼。我選擇了一個單選按鈕。然後點擊「投票」按鈕。但沒有改變。 y始終爲0

AJAX和HTML代碼:

<script> 
    function send_vote() 
      { 
        if (window.XMLHttpRequest) 
        {// code for IE7+, Firefox, Chrome, Opera, Safari 
        xmlhttp=new XMLHttpRequest(); 
        } 
        else 
        {// code for IE6, IE5 
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
        var x; 
        var i; 
        var y = 0; 
        for(i = 1 ; i < 8 ; i++){ 
        x = document.getElementById(i).checked; 

        if(x == true){ 
         y = document.getElementById(i).value; 
         break; 
        } 
        } 



        xmlhttp.onreadystatechange=function() 
        { 
        if (xmlhttp.readyState==4 && xmlhttp.status==200) 
        { 
        var a = xmlhttp.responseText; 

          alert(a); 
        } 
        } 


       xmlhttp.open("GET","oy.php?antivirus="+y,true); 
       xmlhttp.send(); 


      } 

</script> 
<input name="antivirus" type="radio" id="1" value="1" />AVG<br /> 
<input name="antivirus" type="radio" id="2" value="2" />BitDefender<br /> 
<input name="antivirus" type="radio" id="3" value="3" />Eset<br /> 
<input name="antivirus" type="radio" id="4" value="4" />F-Secure<br /> 
<input name="antivirus" type="radio" id="5" value="5" />Kaspersky<br /> 
<input name="antivirus" type="radio" id="6" value="6" />McAfee<br /> 
<input name="antivirus" type="radio" id="7" value="7" />Norton<br /><br /> 
<button type="button" onclick="send_vote()" >Vote</button> 

htaccess文件:

Options +FollowSymlinks 
DirectorySlash Off 
RewriteEngine On 



RewriteRule ^([a-z0-9\-\_]+)$ index.php [L,NC] 

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)$ index.php [L,NC] 

RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/([a-z0-9\-\_]+)$ index.php [L,NC] 
+2

'oy.php'將會匹配你的第一個rewriterule並被重寫爲index.php –

+0

我驗證了JavaScript代碼的工作原理。所以這可能就像Marc所說的那樣。請參閱:http://jsfiddle.net/b6ees/1/ – Halcyon

+0

我不明白。你能解釋和編寫代碼嗎? – hkaraoglu

回答

0

添加一些條件,使您不會改寫現有的文件或目錄:

Options +FollowSymlinks 
DirectorySlash Off 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-z0-9\-\_]+)$ index.php [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)$ index.php [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([a-z0-9\-\_]+)/([a-z0-9\-\_]+)/([a-z0-9\-\_]+)$ index.php [L,NC] 
+0

它不起作用:( – hkaraoglu

+0

當我寫document.write(y)它總是0。 – hkaraoglu