gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 16:26:13 25 4
gpt4 key购买 nike

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com