2016-10-22 30 views
1

好讓我解釋一下我有什麼問題,得到的index.php內容

我在PHP創建MVC結構來創建Web API,並採用了棱角分明的正面。現在我已經創建了一個登錄頁面,並在按鈕點擊事件$http.post("user/login")得到執行,並在控制檯中我得到這樣的輸出。

CONSOLE ERROR 它是輸出整個index.php內容,現在我想知道我在做什麼錯了?

這是我的app.js代碼。

APPJS

這是我的.htaccess

ErrorDocument 404 p1.html 
Header always set Access-Control-Allow-Origin "*" 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php/$1 [QSA,L] 

RewriteCond %{REQUEST_URI} ^/404/$ 
RewriteRule ^(.*)$ p1.html [L] 

Options All -Indexes 

這是我user.php的

<?php 
class user 
{ 
    public static function login(){ 
     echo json_encode(array("in user class model")); 
    } 
} 
?> 

,這是我的index.php

index 我也是使用spl_autoload_register a第二set_include_path, 需要嚴重的幫助.....

回答

1

它看起來像你的要求/user/login被改寫爲/index.php/user/login由於重寫規則

RewriteRule ^(.+)$ index.php/$1 [QSA,L] 

這就是爲什麼你只得到index.php的響應。您需要重寫規則來忽略處理您的API請求的特定路徑 - 通常您會使用像/api這樣的通用前綴,例如您可以使用/api/user/login

有關如何實現此目的的更多詳細信息,請參閱the intro to mod_rewrite

+0

那麼如何寫我的重寫url?請幫忙 – Archish

+0

這個答案應該也有幫助:http://stackoverflow.com/a/8642505/1743938 –

+0

謝謝你告訴我解決我的錯誤的方法。 – Archish