Symfony controller unables to receive AngularJS form post data -
trying send $http.post request angularjs form symfony controller add form content database. can success response "status": 200 @ angularjs side.
however, @ symfony controller, $request->getcontent() empty, returns nothing; $request->getmethod() returns 'get', doesn't make sence me. how can post data in symfony??
p.s. installed fosrestbundle , enabled body listener, param fetcher listener.
i know question duplicated post ajax request angularjs symfony controller, 2 answers of post didn't work me.
my blog.html.twig,
<form name="replyform" ng-submit="sendreply(blog.id)"> preview: {{'{{reply.content}}'}} <br><br> reply: <input type="text" name="content" ng-model="reply.content" /> <input type="submit" value="reply" /> </form>
blog.js,
$scope.reply = {}; $scope.sendreply = function(blogid){ $scope.reply.blog = blogid; $http.post('http://localhost/app_dev.php/blogreply', $scope.reply, {'content-type': 'application/x-www-form-urlencoded'}) .then(function(data){ $scope.message = angular.fromjson(data); }, function(data){ $scope.message = angular.fromjson(data) || "request failed"; }); $scope.reply = {}; }
symfony blogcontroller,
/** * @route("/blogreply", name="blogreply") */ public function replyaction(request $request){ $data = $request->request->get('data', 'default value if data not exist'); return new response ($data); }
the result 'default value if data not exist'.
public function replyaction(request $request) { $data = json_decode($request->getcontent(), true); $request->request->replace($data); echo $request->request->get('foosdaasd'); }
Comments
Post a Comment