好的,让我解释一下我遇到的问题,
我在php中创建了类似MVC的结构来创建Web API,并使用angular作为前端。现在我创建了一个登录页面,并在按钮点击事件$http.post("user/login")
执行,在控制台我得到这样的输出。
它输出整个index.php内容,现在我想知道我做错了什么?
这是我的app.js代码。
这是我的.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
答案 0 :(得分: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。