Javascript AngularJs Http Post未发布
按下按钮时,浏览器上不会发生任何操作,并且在我的REST端点上没有新用户。registerUser()由按下按钮触发。我紧跟着一个教程 html部分Javascript AngularJs Http Post未发布,javascript,angularjs,node.js,Javascript,Angularjs,Node.js,按下按钮时,浏览器上不会发生任何操作,并且在我的REST端点上没有新用户。registerUser()由按下按钮触发。我紧跟着一个教程 html部分 <div class="section no-pad-bot" ng-controller="registerController" id="index-banner"> 废话废话 <form> <div class="row">
<div class="section no-pad-bot" ng-controller="registerController" id="index-banner">
废话废话
<form>
<div class="row">
<div class=" input-field col s6 offset-s3">
<i class="material-icons prefix">account_circle</i>
<input type="text" class="validate" ng-model="user.username" placeholder="Username">
</div>
</div>
<div class="row">
<div class=" input-field col s6 offset-s3">
<i class="material-icons prefix">account_circle</i>
<input type="text" class="validate" ng-model="user.email" placeholder="Email">
</div>
</div>
<div class="row">
<div class=" input-field col s6 offset-s3">
<i class="material-icons prefix">account_lock</i>
<input type="text" class="validate" ng-model="user.password" placeholder="Password">
</div>
</div>
<button class="btn waves-effect waves-light" type="submit" ng-click="registerUser()">Submit
<i class="material-icons right">send</i>
</button>
</form>
会计圈
会计圈
帐户锁定
提交
发送
在clientapp.js中
myApp.controller('registerController', function ($scope, $http) {
$scope.registerUser = function () {
// use $.param jQuery function to serialize data from JSON
var data = $.param({
hashword: $scope.password,
username: $scope.username,
email: $scope.email,
});
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('/api/users', data, config)
.success(function (data, status, headers, config) {
console.log("successful post");
$scope.PostDataResponse = data;
})
.error(function (data, status, header, config) {
console.log("failed post");
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
};
myApp.controller('registerController',函数($scope,$http){
$scope.registerUser=函数(){
//使用$.param jQuery函数从JSON序列化数据
变量数据=$.param({
hashword:$scope.password,
用户名:$scope.username,
电子邮件:$scope.email,
});
变量配置={
标题:{
“内容类型”:“application/x-www-form-urlencoded;charset=utf-8;”
}
}
$http.post('/api/users',数据,配置)
.success(函数(数据、状态、标题、配置){
console.log(“成功发布”);
$scope.PostDataResponse=数据;
})
.错误(功能(数据、状态、标题、配置){
console.log(“失败的post”);
$scope.ResponseDetails=“数据:”+数据+
“
状态:”+状态+
“
标题:”+标题+
“
配置:”+config;
});
};
因为在html页面中,您分别指的是user.username
、'user.email'和user.password
,而不是username
、email
和password
试着换成下面的
<input type="text" class="validate" ng-model="username" placeholder="Username">
<input type="text" class="validate" ng-model="email" placeholder="Email">
<input type="text" class="validate" ng-model="password" placeholder="Password">
希望对您有所帮助,因为在html页面中,您分别指的是
user.username
,“user.email”和user.password
,而不是username
,email
和password
试着换成下面的
<input type="text" class="validate" ng-model="username" placeholder="Username">
<input type="text" class="validate" ng-model="email" placeholder="Email">
<input type="text" class="validate" ng-model="password" placeholder="Password">
希望它有帮助我没有在您的范围内看到
user
对象,将ng model=“user.email”
更改为ng model=“email”,类似地ng model=“user.username”
更改为ng model=“username”
和ng model=“user.password”
更改为ng model=“password”
我在您的范围内没有看到user
对象,请将ng model=“user.email”
更改为ng model=“email”,类似地ng model=“user.username”
更改为ng model=“username”
和ng model=“user.password”
更改为ng model=“password”
谢谢,但出于某种原因,鼠标单击按钮不表示任何问题,也不表示什么?请尝试在浏览器的开发人员控制台中查看有效负载。谢谢,但出于某种原因,鼠标单击按钮也不表示任何问题,也不表示什么问题?请尝试在浏览器的开发人员控制台中查看有效负载。