angularjs - Params with angular form submit -
i'm trying set dummy form angular. have form set i'd fake params sent , see outcome. think it's called serializing params.
please consider following code on success $scope.message = "message sent " + $scope.formdata
currently returns message sent [object object]
i'd return params sent message sent {"order": ["company": "test", "phone": "1111"]}
here full code
angular.module("app").controller "contactcontroller", ($scope, $http) -> $scope.formdata = {} $scope.processform = -> console.log $scope.formdata $http( method: "post" url: 'process.php' data: $scope.formdata ).success( (data) -> # if successful, bind success message message $scope.message = "message sent " + $scope.formdata $scope.formdata = '' ).error (status) -> console.log "an error occured processign form" # if not successful, bind errors error variables $scope.errorfirstname = data.errors.firstname $scope.errorlastname = data.errors.lastname
this simple. when call tostring()
on object (what you're doing there), instead of being helpful, javascript returns [object object]
.
easy remedy, change $scope.formdata
json.stringify($scope.formdata)
. thus:
$scope.message = "message sent " + json.stringify($scope.formdata)
Comments
Post a Comment