AngularJS:无法发布到服务器PHP文件(获取404)

AngularJS:无法发布到服务器PHP文件(获取404),php,.htaccess,angularjs,http-status-code-404,yeoman,Php,.htaccess,Angularjs,Http Status Code 404,Yeoman,大家好,谢谢你们抽出时间! 我是AngularJS的新手,目前正在使用服务器端部分制作我的第一张表单。 我在VirtualBox上运行,使用Yeoman进行设置 my HTML有两个字段:用户名和密码,它们依次传递到js文件: function authUsers($scope, $http) { $scope.url = '../api/authUsersService.php'; // The url of our search // The function that will be e

大家好,谢谢你们抽出时间! 我是AngularJS的新手,目前正在使用服务器端部分制作我的第一张表单。 我在VirtualBox上运行,使用Yeoman进行设置

my HTML有两个字段:用户名和密码,它们依次传递到js文件:

function authUsers($scope, $http) {
$scope.url = '../api/authUsersService.php'; // The url of our search

// The function that will be executed on button click (ng-click="search()")
$scope.loginAttempt = function() {

    // Create the http post request
    // the data holds the keywords
    // The request is a JSON request.
    alert($scope.session.username);alert($scope.session.password);
    $http.post($scope.url, { "username" : $scope.session.username, "password" : $scope.session.password}).
    success(function(data, status) {
        $scope.status = status;
        $scope.data = data;
        $scope.result = data; // Show result from server in our <pre></pre> element
        alert(data);
    })
    .
    error(function(data, status) {
        $scope.data = data || "Request failed";
        $scope.status = status;
        alert(data);         
        alert(status);
    });
};
}
函数authUsers($scope,$http){
$scope.url='../api/authUsersService.php';//我们搜索的url
//将在按钮单击时执行的函数(ng click=“search()”)
$scope.loginattent=function(){
//创建http post请求
//数据包含关键字
//该请求是一个JSON请求。
警报($scope.session.username);警报($scope.session.password);
$http.post($scope.url,{“用户名”:$scope.session.username,“密码”:$scope.session.password})。
成功(功能(数据、状态){
$scope.status=状态;
$scope.data=数据;
$scope.result=data;//在元素中显示来自服务器的结果
<?php
$data = file_get_contents("php://input");

$objData = json_decode($data);

// Create connection
$con=mysqli_connect("example.com","peter","abc123","my_db");

// Check connection
if (mysqli_connect_errno($con))  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "select userID from authUsers where username = " . $objData->username . " and password = " . $objData->password);

if ($result->num_rows > 0) {
    $row = $result->fetch_array(MYSQLI_ASSOC);
    echo $row["userID"];
} else {
    echo "";    
}
?>
警报(数据); }) . 错误(功能(数据、状态){ $scope.data=data | |“请求失败”; $scope.status=状态; 警报(数据); 警报(状态); }); }; }
我收到2个警报(用户名、密码)。 此文件和HTML本身位于Angular的应用程序文件夹下。在文件夹外,在同一个包含文件夹中:我创建了“API”文件夹。这是文件api/authUsersService.php:


当提交HTML表单时,我从控制器(js文件)获取所有警报,包括“.error”警报。我在错误中得到的数据是:“无法发布到/api/authUsersService.php”,状态是“404”

我找不到任何解决办法。尝试了var\www\http文件夹中的.htaccess,但没有帮助。 请帮我成功获取PHP服务器代码! 谢谢

在URL中使用“./”可以很好地表明您做错了什么


您不能“跳出”web服务器的根目录,因此需要将其放在“app”目录中,以便web访问。

尝试直接访问服务器url(在浏览器中)。404很可能意味着服务器地址不正确。我不能直接访问URL(记住这是一个开发服务器),我也在那里得到了404。我认为问题在于路线。我不知道怎么解决它。