mod_rewrite似乎弄乱了我的ajax post脚本

时间:2022-08-23 01:10:55

my getLikes script that I mentioned in a previous question doesnt work at all when I rewrite the url to a cleaner version...is that b/c it is a Post request? Everything else works fine, like the get part that looks up the user profile. here is the mod_rewrite:

当我将url重写为更干净的版本时,我在上一个问题中提到的getLikes脚本根本不起作用...是b / c它是Post请求吗?其他一切正常,就像查找用户配置文件的get部分一样。这是mod_rewrite:

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

and here is the ajax: it is supposed to get the ID and then posts to a page which returns whether the user likes this profile...its basically a like button

这里是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();
        }
    });
}

1 个解决方案

#1


0  

Change url: "likelist.php" to url: "/likelist.php".

将url:“likelist.php”更改为url:“/ likelist.php”。

Use absolute path, URI with everything behind domain name.

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

http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]

http_URL =“http:”“//”host [“:”port] [abs_path [“?”查询]]

By adding / at the beginning or URI, it is nearly equal like you've written http://example.com/.

通过在开头或URI处添加/,它几乎与您编写的http://example.com/相同。

Because you've rewritten URL to profile/name, it looks for profile/name/likelist.php which clearly doesn't exist.

因为您已将URL重写为个人资料/名称,所以它会查找明显不存在的个人资料/名称/ likelist.php。

#1


0  

Change url: "likelist.php" to url: "/likelist.php".

将url:“likelist.php”更改为url:“/ likelist.php”。

Use absolute path, URI with everything behind domain name.

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

http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]

http_URL =“http:”“//”host [“:”port] [abs_path [“?”查询]]

By adding / at the beginning or URI, it is nearly equal like you've written http://example.com/.

通过在开头或URI处添加/,它几乎与您编写的http://example.com/相同。

Because you've rewritten URL to profile/name, it looks for profile/name/likelist.php which clearly doesn't exist.

因为您已将URL重写为个人资料/名称,所以它会查找明显不存在的个人资料/名称/ likelist.php。