当从angularjs发送数据到php文件时,它在我的本地主机中不写文件名时效果很好,但是当我引入文件名时,数据没有发送,我收到404错误。
这是什么意思: 当我使用http://127.0.0.1/social/时,帖子请求工作得非常好。但是在使用http://127.0.0.1/social/index.php时,我收到了404错误。这是我的html部分:'index.php'
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jquery-3.1.0.js"></script>
<script src="js/angular.min.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script src="js/jsfile.js"></script>
</head>
<body ng-app="socialApp">
<!-- Modal HTML for login -->
<div id="loginModal" class="modal fade" ng-controller="loginController">
<div class="modal-dialog">
<form method = "POST" action = "">
<div class="modal-content">
<div class="modal-header text-center">
<h3 class="modal-title">Login</h3>
</div>
<div class="modal-body">
<div class="form-group text-center">
<h5 style="color: red;" id = "loginError"></h5>
</div>
<div class="form-group">
<input type="text" ng-model = "Username" class="form-control input input-lg" name = "username" placeholder="Email / Username" required="required" />
</div>
<div class="form-group">
<input type="password" ng-model = "Password" class="form-control input input-lg" name = "password" placeholder="Password" required="required" />
</div>
<div class="form-group">
<input type = "submit" ng-click = "loginFunction()" class = "btn btn-success btn-lg btn-block" name = "loginBtn" value = "Continue" />
</div>
<div class="form-group">
<h5><a href="#forgotPasswordModal" data-toggle="modal" data-dismiss="modal">Forgot password</a></h5>
</div>
</div>
<div class="modal-footer text-center">
<div class="form-group text-center">
<h5>Not a member yet?<a href="#signUpModal" data-toggle="modal" data-dismiss="modal"> Join now.</a></h5>
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
以下是我的angularjs代码'js / jsfile.js'
var app = angular.module('socialApp',[]);
app.controller('loginController',['$scope','$http','$window',
function($scope,$http,$window){
$scope.loginFunction = function(){
var what = "login";
var username = $scope.Username
var password = $scope.Password
var request = $http({
method: "post",
url: window.location.href + "php/savefetch.funct.php",
data: {
what:what,
username:username,
password:password
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
request.success(function (data) {
alert(data);
});
};
}]);
我在'php / savefetch.funct.php'上获取数据,如下所示,
$postdata = file_get_contents("php://input",true);
$request = json_decode($postdata);
@$what= $request->what;
@$username= $request->username;
@$password= $request->password;
echo $what." ".$username." ".$password;
感谢。