javascript - angular $http not sending any value into server -
i'm trying send json data server, , want response text server.
this code :
app.directive("registersection",['$http',function($http){ return{ restrict : "e", templateurl : "view/register-section.html", controller : function(){ this.regdata = {}; this.adddata = function(){ // send data $http({method:'post',url:'http://url.com/account/register',data:json.stringify(this.regdata)}).then(function(dt){ alert(json.stringify(dt)); },function(dt){ alert(json.stringify(dt)); }); }; }, controlleras : "reg" }; }]);
this html code :
<form name="registerform" ng-submit="registerform.$valid && reg.adddata()" novalidate> <input type="text" name="name" ng-model="reg.regdata.name" placeholder="your name" required><br /> <input type="email" name="email" ng-model="reg.regdata.email" placeholder="your email" required><br /> <input type="password" name="password" ng-model="reg.regdata.password" placeholder="your password" required><br /> <p>{{reg.regdata}}</p> <button type="submit">register</button>
i've see angular docs, , server still not getting values client. i've see same problem in stack overflow still doesn't have answer problem.
sorry bad english, thanks.
i think issue caused way add data $http call. try change controller function follow:
controller : function(){ this.regdata = {}; //send data this.adddata = function(){ var url = 'http://url.com/account/register'; $http.post(url, this.regdata).then(function(dt){ console.log(dt); },function(dt){ console.log(dt); }); }; }
you not have stringify since $http service you.
note: url not working me, cannot test part of code.
Comments
Post a Comment