【发布时间】:2017-09-20 06:06:05
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<title>login</title>
<script src="angular.min.js"></script>
<style type="text/css">
#a{
display: none;
}
</style>
</head>
<body>
<div ng-app="myapp" ng-controller="myctrl">
<p>Input something in the input box:</p>
<input type="text" ng-model="username" placeholder="username"><br>
<input type="password" name="password" ng-model="password" placeholder="password"><br>
<button ng-click="login()">login</button>
<p id="a">
{{ resmsg }}<br>
<br></p>
</div>
<script type="text/javascript">
var app= angular.module('myapp',[]);
app.controller('myctrl', function ($scope , $http, $templateCache) {
$scope.resmsg ="";
$scope.login = function()
{
$http({
method: 'POST',
url:'http://localhost/ng/myphp.php',
data:{username : $scope.username, password : $scope.password},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
cache: $templateCache
}).success(function(response) {
$scope.resmsg = response;
}).error(function(response){
})
$scope.resmsg = response;
}
})
</script>
</body>
</html>`
myphp.php
<? php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$username = $request->username;
$password = $request->password;
if($username == "admin" && $password== "admin"){
echo "1";
}
else {
echo "0";
}
?>
我正在尝试使用 angularjs 创建一个简单的登录表单,我有 php 尝试使用 http.post() 方法将我的表单数据发送到 php 文件
在 Angular js 中,但没有得到任何响应并得到 errormsg (screenshot) ,错误就像没有函数一样 成功 帮我摆脱这个错误
【问题讨论】:
标签: javascript php html angularjs