我只是对angularjs的新手我更多关于jquery而且我只是尝试在post请求中使用angular与ajax的工作方式相同。但当我看到我的console.log()时,我看到了一个问题,我的验证输出有一个html标签
输出中
https://i.stack.imgur.com/G2Lbx.jpg
** CONTROLLER(codeigniter)**
public function auth(){
$obj = json_decode(file_get_contents('php://input'));
$_POST = json_decode(file_get_contents('php://input'),true);
$this->form_validation->set_rules('name','Name','required|is_unique[users.name]');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('cpassword','Confirm Password','required');
if($this->form_validation->run()==FALSE){
echo json_encode(validation_errors());
}else{
echo json_encode("no error");
}
}
MY ANGULARJS
<script type="text/javascript">
var app = angular.module('app', []);
var base_url = window.location.origin+"/";
app.controller('myCtrl', function($scope,$http) {
$scope.message = "";
$scope.formData = {}
$scope.submit = function(){
var regdata = {
url: base_url+"main/auth",
method: "POST",
data: {
name: $scope.name,
password: $scope.password,
cpassword: $scope.cpassword
},
headers: {'Content-Type': 'application/json'},
}
$http(regdata).then(function successCallback(response) {
$scope.message = response.data;
console.log($scope.message);
}, function errorCallback(response) {
alert('Something Went Wrong! :( ');
});
}
});
</script>
我的观点
<h3>Sign Up Now</h3>
<form method="post" id="form_signup" ng-submit="submit()">
<p style="color:white">{{ message }}</p>
<!-- <p ng-model="message"></p> -->
<input placeholder="Name" ng-model="formData.name" type="text" />
<span class="icons i3"><i class="fa fa-user" aria-hidden="true"></i></span>
<!-- <input placeholder="E-MAIL" name="email" type="email" />
<span class="icons i4"><i class="fa fa-envelope-o" aria-hidden="true"></i></span> -->
<input placeholder="PASSWORD" ng-model="formData.password" type="password" />
<span class="icons i4"><i class="fa fa-key" aria-hidden="true"></i></span>
<input placeholder="CONFIRM PASSWORD" ng-model="formData.cpassword" type="password" />
<input type="submit" value="Sign UP" name="login">
</form>