【问题标题】:mod_rewrite seems to mess up my ajax post scriptmod_rewrite 似乎弄乱了我的 ajax post 脚本
【发布时间】:2012-12-09 22:19:42
【问题描述】:

当我将 url 重写为更简洁的版本时,我在上一个问题中提到的 getLikes 脚本根本不起作用……那是 b/c 它是 Post 请求吗?其他一切正常,例如查找用户配置文件的获取部分。 这是 mod_rewrite:

RewriteEngine on
RewriteRule ^profile/([^/\.]+)/?$ profile.php?p=$1 [L]

这里是ajax:它应该获取ID,然后发布到一个页面,该页面返回用户是否喜欢这个配置文件......它基本上是一个喜欢按钮

public function likesScript($p){?>
    <script>

    //display list of people who like this
    function getLikes(){
    $.ajax({
        type: "POST",
        url: "likelist.php",

        data: { p: "<?php echo $_GET['p']?>"}
    }).success(function(res) {

        $("#likedBy").html(res); 
        //console.log(res); 

        if($('li#<?PHP echo $_SESSION['userId']; ?>').length){
            $(".Like").hide();
            $(".UnLike").fadeIn();
        } else {  
            $(".UnLike").hide();
            $(".Like").fadeIn();
        }
    });
}

【问题讨论】:

  • 在 AJAX 请求发生时查看浏览器的网络控制台。 HTTP 响应代码是什么,如果有错误,您会看到什么错误? Th RewriteRule 不应该干扰,因为它不匹配 likelist.php

标签: php jquery ajax apache mod-rewrite


【解决方案1】:

url: "likelist.php" 更改为url: "/likelist.php"

使用绝对路径,URI 与域名后面的所有内容。

http_URL = "http:" "//" 主机 [ ":" 端口 ] [ abs_path [ "?"查询]]

通过在开头或 URI 中添加/,它几乎等于您编写的http://example.com/

因为您已将 URL 重写为 profile/name,所以它会查找显然不存在的 profile/name/likelist.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    相关资源
    最近更新 更多