0
<script>
var app = angular.module("myapp",[]);

app.controller("usercontroller",function($scope,$http){
$scope.insertData = function(){
  $http.post(
    "insert.php",    
    {'yourName':$scope.yourName, 'lstName':$scope.lstName,
 'passwrd':$scope.passwrd}).success(function(data){
      alert(data);
    });
}
});

I have this code and console returns an error that says "success is not function"how do I fix it?

2 Answers 2

1

use then instead success .

.then(onSuccess)
function onSuccess(data){
}

And i think in you should do like that

html

<input ng-model="formData.yourName">
<input ng-model="formData.lstName">
<input ng-model="formData.password">

in js

       function yourcontroller($scope){
        var $scope.formData={};
            $http({
            method:'POST',
            url:'insert.php',
            data:$.param($scope.formData)
            headers : { 'Content-Type': 'application/x-www-form-urlencoded' }

            })  .then(onSuccess,onError)
        function onSuccess(data){
      //handle success
        }
        function onError(reason){
      //handle error
}
        }
Sign up to request clarification or add additional context in comments.

Comments

0

.success is depreciated, Use .then. Like :

 .then(function(data){
    alert(data);// handle data
  }, function(error) {
        //handle error
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.