There is a controller:

betdeskApp.controller('regController', function ($scope, $http) { $scope.email = ''; $scope.password = ''; $scope.action = 'registration'; $scope.SendRequest = function() { $http.post(CreateHref($scope.action, $scope.email, $scope.password)).success(function (data) { $scope.regAnswer = data; console.log(data); }); } }); function CreateHref(action, email, password) { var str = "../model/web/index.php" + "?" + "action=" + action + "&" + "email=" + email + "&" + "password=" + password; // console.log(str); return str; } 

When sending this request, the answer comes in emptiness.
The server is php and works correctly.
Maybe I did not take into account something in the controller when requested?

Form submission code:

 <form class="col-sm-6" action="../model/web/index.php" method="post"> <div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> <input type="hidden" name="action" value="registration"> <input id="email" type="text" class="form-control" name="email" placeholder="Email" value="" ng-model="email"> </div><br /> <div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> <input id="password" type="password" class="form-control" name="password" placeholder="Password" value="" ng-model="password"> </div><br /> <div class="input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-repeat"></i></span> <input id="password" type="password" class="form-control" name="confirmPassword" placeholder="Confirm Password" ng-model="confPassword"> </div><br /> <div class="input-group"> <button type="submit" class="btn btn-primary">Submit</button> </div> </form> 

Here is what I get in the log: enter image description here

  • if something doesn’t work, the first thing you need to do is watch the errors in the console - Grundy
  • and also to check what exactly happens on the server. Perhaps it is precisely the void that it returns - Grundy
  • You can edit your question and add the missing information to it using the button with the help of the button. Question under Grundy
  • judging by the answer - the server returns an empty string. It is worth going through the steps of the server function and see the error - Grundy
  • @Grundy when I send a request through action , I register in the database, but when I send it via the controller, I don’t. In essence, I convey the same thing - Roman Timokhov

2 answers 2

Should work:

 var config = { headers : { 'Content-Type': 'application/x-www-form-urlencoded' } } var data = "action=registration&email=test@gmail.com&password=123456&confirmPassword=123456"; $http.post('../model/web/index.php', data, config) .success(function (data, status, headers, config) { console.log(data); }) .error(function (data, status, header, config) { console.log(data); }); 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nofate

Taras was in the right direction, his code:

  var config = { headers : { 'Content-Type': 'application/x-www-form-urlencoded' } } var data = "action=registration&email=test@gmail.com&password=123456&confirmPassword=123456"; $http.post('../model/web/index.php', data, config) .success(function (data, status, headers, config) { console.log(data); }) .error(function (data, status, header, config) { console.log(data); }); 

The plug-in turned out that the data variable needs to be properly prepared for transmission. I did it like this:

 var data = $.param({ "action": $scope.action, "email": $scope.email, "password": $scope.password }); 

After that, everything worked fine