【问题标题】:.htaccess file doesnt allow ajax get command?.htaccess 文件不允许 ajax get 命令?
【发布时间】:2014-03-03 16:43:47
【问题描述】:

我的问题是这个代码:xmlhttp.open("GET","oy.php?antivirus="+y,true);

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 将匹配您的第一个重写规则并被重写为 index.php
  • 我验证了 JavaScript 代码有效。所以这可能就像 Marc 所说的那样。见:jsfiddle.net/b6ees/1
  • 我不明白。你能解释和写代码吗?
  • 如何匹配第一个重写规则?

标签: php ajax .htaccess


【解决方案1】:

添加一些条件,这样您就不会重写现有文件或目录:

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]

【讨论】:

  • 当我写 document.write(y) 时它总是 0。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-12
  • 2018-09-19
  • 2014-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多