【问题标题】:Javascript rating bar don't work with modrewrite urlsJavascript 评分栏不适用于 modrewrite url
【发布时间】:2011-11-19 08:27:00
【问题描述】:

在我的脚本中,这个函数部分构建链接:

if ($type == "mod_rewrite") {
    $prepend = "";
    $append = ".html";

} else if ($type == "query_string") {
        $prepend = 'index.php?params=';
        $append = "/";
}
//
//
//
    $gamelink = 'game/id/gamename' (example)
    /* 'game' is a fixed string.  
        'id' and 'gamename' are variables) */

我的 .htacess 如下:

RewriteEngine on
RewriteRule  ^(.*)\.html$ index.php?params=$1 [NC,L]

问题:

我在游戏页面中有一个在查询字符串模式下完美运行的 ajax 评分栏:

(在此示例中:gamename = 'Arm Copter' 和 gameid = '3')

游戏链接:

http://localhost/gss/index.php?params=game/3/Arm-Copter/

评分链接(鼠标悬停的星星图片)

http://localhost/gss/plugins/ajax_star_rater/db.php?j=10&q=arm_copter&t=127.0.0.1&c=10

使用 ModRewrite: 游戏链接:

http://localhost/gss/game/3/Arm-Copter.html

评级链接(星号缺失,仅显示与星号对应的数字):

http://localhost/gss/game/3/plugins/ajax_star_rater/db.php?j=10&q=arm_copter&t=127.0.0.1&c=10

这里的问题,似乎是 url 部分 'game/id/' 插入,因为 db.php 的正确路径是:

http://localhost/gss/plugins/ajax_star_rater/db.php

而不是:

http://localhost/gss/**game/3/**plugins/ajax_star_rater/db.php

我花了 2 天时间搜索和测试各种方法,但我没有找到解决方案。我需要一个不重写 ajax 评级栏或重写为正确路径的规则。

问候,

大三 - 巴西。

【问题讨论】:

  • 您使用哪些 URI 作为参考?您可能使用了“错误”的(可能是相对的)。
  • Hi Gumbo, // 我本地服务器上 Script 的本地路径:$cfg['instdir'] = 'D:/Program Files/wamp/www/gss/';我的脚本的 URL: $cfg['baseurl'] = 'localhost/gss'; ajax 星级评定者的路径:D:/Program Files/wamp/www/gss/plugins/ajax_star_rater/db.php 在我的 index.php 中,我有 ajax 星级评定者的链接:

标签: php javascript .htaccess mod-rewrite


【解决方案1】:

我找到了解决方案:您必须编辑 rating.js -

function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL

// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';

xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null); 
}

你需要改变这一行:

xmlhttp.open('get', '../../rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units); 

rpc.php 之前的部分必须是../../

【讨论】:

    【解决方案2】:

    在调用插件 (http://localhost/gss/game/3/plugins/ajax_star_rater/db.php) 的评级链接的 html 中,您可能使用的是当前文件夹的相对路径,听起来您需要使用相对于根文件夹的路径。

    代替:

    <a href="plugins/ajax_star_rater/db.php">Rate me!</a>
    

    您需要添加一个以 / 开头的链接并写入脚本的完整路径:

    <a href="/gss/plugins/ajax_star_rater/db.php">Rate me!</a>
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2021-03-04
      • 2014-09-15
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      相关资源
      最近更新 更多