【问题标题】:getJSON and mod rewritegetJSON 和 mod 重写
【发布时间】:2011-10-25 17:07:22
【问题描述】:

我正在使用以下代码从我的服务器检索 json 格式的值:

 $(document).ready(function(){
 $.getJSON("http://127.0.0.1/test/echo.php?jsoncallback=?",     {
        value: 'hello',
        },      function(data){
                $('#div').html(data.test);
          }); });

如您所见,$.getJSON 网址现在是:http://127.0.0.1/test/echo.php?jsoncallback=?

但我更喜欢:http://127.0.0.1/test/echo/

在我的服务器上,我正在使用以下 mod 重写代码:

RewriteRule 上的 RewriteEngine ^test/echo/([^/.]+) test/echo.php?value=$1 [L]

当我在浏览器中输入 URL (http://127.0.0.1/test/echo/hello) 时,一切正常,但我想知道如何在 $.getJSON 请求中使用干净的 url .因为由于某种原因,我喜欢的网址现在不起作用。

【问题讨论】:

    标签: javascript jquery json mod-rewrite getjson


    【解决方案1】:

    您的查询字符串似乎在您的 RewriteRule 中丢失了,试试QSA (Query String Append) flag

    RewriteRule ^test/echo/([^/.]+) test/echo.php?value=$1 [L,QSA]
    

    这会将 URL 的 &jsoncallback=? 部分传递给 test/echo.php 以及 value 参数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多