好的,让我解释一下我遇到的问题,
我在 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
这是我的用户.php
<?php
class user
{
public static function login(){
echo json_encode(array("in user class model"));
}
}
?>
这是我的index.php
我还使用 spl_autoload_register
和 set_include_path
,
需要认真的帮助......
最佳答案
由于重写规则,您对 /user/login
的请求似乎被重写为 /index.php/user/login
RewriteRule ^(.+)$ index.php/$1 [QSA,L]
这就是为什么您只是从 index.php
获得响应。您需要重写规则来忽略处理 API 请求的特定路径 - 通常您会使用像 /api
这样的通用前缀,例如您可以使用 /api/用户/登录
。
有关如何实现此目的的更多详细信息,请参阅 the intro to mod_rewrite .
关于javascript - 在 Angular js中获取index.php内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40191550/