我的問題是此代碼: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]
'oy.php'將會匹配你的第一個rewriterule並被重寫爲index.php –
我驗證了JavaScript代碼的工作原理。所以這可能就像Marc所說的那樣。請參閱:http://jsfiddle.net/b6ees/1/ – Halcyon
我不明白。你能解釋和編寫代碼嗎? – hkaraoglu