【问题标题】:getting index.php content in angular js在 Angular js 中获取 index.php 内容
【发布时间】:2017-03-04 15:28:33
【问题描述】:

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

我在 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

我也在使用spl_autoload_registerset_include_path, 需要认真的帮助.....

【问题讨论】:

    标签: javascript php angularjs .htaccess


    【解决方案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

    【讨论】:

    猜你喜欢
    • 2020-02-07
    • 2020-03-21
    • 2017-09-30
    • 2016-08-08
    • 1970-01-01
    • 2015-02-07
    • 2018-11-26
    • 1970-01-01
    • 2018-01-16
    相关资源
    最近更新 更多