【问题标题】:data is not fetching by using ajax with mod_rewrite使用带有 mod_rewrite 的 ajax 无法获取数据
【发布时间】:2014-01-16 05:45:09
【问题描述】:

请多多包涵,我不知道如何解释我的问题,而且我是 mod re_writing 的新手,我有两页

  1. index.php
  2. search.php

index.php 有一个搜索字段和一个可以获取数据的 div。搜索字段使用 Ajax 从数据库中提供即时结果。

作为

具有即时结果的搜索字段

当我在 index.php 上时,它给了我正确的结果,在这里我使用了一个重写规则,它变成了

http://localhost/user_profiles/index?u=tol

进入

http://localhost/user_profiles/index/u/tol

并给我个人资料视图

两个网址都给了我正确的结果,但问题在于 ajax,当我打开时

http://localhost/user_profiles/index?u=tol

ajax 工作得很好,给了我正确的结果,但是当我在

    http://localhost/user_profiles/index/u/tol

它给出了奇怪的结果

我不知道如何解决这是我的 re_write 规则

Options +FollowSymLinks
RewriteEngine on
RewriteRule u/(.*) index.php?u=$1 [L,QSA]

index.php 的另一个规则只是索引

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

我的 ajax 查询是

maq.open('GET','search?q='+userVal,true);

请帮帮我。

【问题讨论】:

    标签: php ajax .htaccess mod-rewrite


    【解决方案1】:

    请记住,文件引用在 JavaScript 中是相对的。

    当您在重新编写的页面上时,您需要使用以下方法将链接更新为search:

    maq.open('GET', '../../search?q='+userVal, true);
    

    基本上,我们所在的虚拟目录的两个目录(即从user_profiles/index/u/tol/search 到user_profiles/index/search)。

    或者,您可以使用前导 / 相对于根来指定它,例如:

    maq.open('GET', '/user_profiles/index/search?q='+userVal, true);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 2013-03-23
    • 1970-01-01
    • 2016-03-24
    相关资源
    最近更新 更多