javascript - 在 Angular js中获取index.php内容

标签 javascript php angularjs .htaccess

好的,让我解释一下我遇到的问题,

我在 php 中创建了类似 MVC 的结构来创建 Web API,并使用 Angular 作为前端。现在我创建了一个登录页面,并在按钮单击事件 $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

这是我的用户.php

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

这是我的index.php

index 我还使用 spl_autoload_registerset_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/

相关文章:

javascript - jQuery 函数未在另一个函数之前执行

javascript - 使用 google 图表 api 和 sql

javascript - 在 Angularjs 中获取对 Controller 的未定义依赖

javascript - 使用 Ionic Framework 和 AngularJS 嵌入社交网络的发布

javascript - AngularJS 分页 orderBy 只影响显示的页面

javascript - 即使我有链接,如何强制打开我的 jQuery 对话框?

Javascript 检查日期并运行脚本

javascript - Google 日历返回无效的 json 文件

php - 我的 CentOS linux 机器上的 PHP 是什么用户?根?

php - html2pdf页码