我正在尝试使用AngularJS在PHP中使用REST API在数据库中添加数据。但这样做我收到了错误,
POST http://localhost/spa/sp-cart/server_scripts/rest_api.php 404(未找到)
以下是我的代码,
signup.html
<div class="container main">
<!--<div class="alert alert-info" ng-show="wishToCart">{{duplicateData}}</div>-->
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<div class="account-wall">
<form action="" method="">
<div id="my-tab-content" class="tab-content">
<div class="tab-pane active" id="register">
<div class="form-signin">
<input type="text" ng-model="username" class="form-control" placeholder="User Name ..." required autofocus>
<input type="email" ng-model="useremail" class="form-control" placeholder="Emaill Address ..." required>
<input type="password" ng-model="userpassword" class="form-control" placeholder="Password ..." required>
<button ng-click="signup()" type="submit" class="btn btn-lg btn-default btn-block" value="Sign Up">Sign Up</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
controllers.js
angular.module('cartApp.signup.controllers', []).
controller('SignupController',
['$scope', '$state', '$log', '$rootScope', '$http',
function ($scope, $state, $log, $rootScope, $http) {
$log.log('inside login controller');
$scope.signup = function () {
$log.log('signup data stored');
$http.post('../server_scripts/rest_api.php',
{ 'username': $scope.username,
'email': $scope.useremail,
'password': $scope.userpassword
}).success(function (data, status, headers, config) {
$log.log("Data Inserted Successfully");
}).error(function (data, status) {
$log.log('Data Insert Error');
});
}
}
]);
对于REST API,我使用以下链接中的代码(进行必要的更改以匹配我的数据库名称,密码和用户名)
Creating a simple REST API in PHP
请帮助我理解我的rest_api.php文件遇到404错误的主要问题。我有正确的道路。
提前谢谢。
注意:我是新手在数据库中插入数据。请一步一步帮助我。