2014-01-15 51 views
0

請大家多多包涵我,我怎麼不解釋我的問題,我是新與國防部re_writing我有數據不被使用Ajax和mod_rewrite的獲取

  1. 兩頁的index.php
  2. 的search.php

index.php有一個搜索字段和一個div,其中數據是fetch.and搜索字段使用Ajax從數據庫中給出即時結果。即時

search field with instant results

搜索領域的結果

當我上的index.php它給我正確的結果,在這裏我使用的是重寫規則果然

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

納入

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

,並給我的個人資料視圖

profile view

兩個網址給我正確的結果,但問題是與阿賈克斯,當IM上

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

AJAX完美的作品,並給我正確的結果,但是當我在

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

它給出奇怪的結果爲 weird result

我無法弄清楚如何在這裏解決它是我的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); 

請幫幫我。

回答

2

請記住,文件引用在JavaScript中是相對的。

當你重新編寫的頁面上,你需要使用更新的鏈接search

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

從本質上講,這兩個目錄了,從我們的虛擬目錄(即從user_profiles/index/u/tol/searchuser_profiles/index/search)。

或者,您可以使用領先/指定它相對於根目錄,例如:

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

現在只搜索在http工作://本地主機/ user_profiles /索引/ U/TOL,但不工作對於http:// localhost/user_profiles/index? – Null

+0

@Null看到更新的答案。 – BenM

+0

謝謝你,我非常感謝主席:) – Null