akuk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks, I am creating a web application having AngularJS as frontend and Perl as backend. I am using Perl Dancer and I am used to it but AngularJS is new to me. I am trying to make a simple RESTfull call to web app but It is not working. Below is the complete Code

<div ng-app="formmodule"> <form method="get" ng-submit="submit()"> <div ng-controller="submitController"> Name :<input type="text" ng-model="uname"></br> pwd:<input type="password" ng-model="pwd"><br> <br> <button ng-click="submit()">submit</button> </div> </form> </div> <script> var app=angular.module("formmodule",[]); app.controller("submitController",function submit($scope,$http){ var uname = $scope.uname; var pwd= $scope.pwd; var url = 'http://localhost:5000/users/uname'; $http.get(url).success( function(data) { $scope.output = data; }); }); </script> </body> ##### Perl App.pm Code package TarView::App; use Dancer2; our $VERSION = '0.1'; get '/' => sub { template 'index'; }; get '/users/:uname' => sub { my $unam = params->{uname}; return $unam; }; true;

If I hit the http://localhost:5000/users/uname to the web browser it is working fine and returning the name of the user but from AngJS it's not working.

Replies are listed 'Best First'.
Re: Perl Restfull call by Angular JS not working
by Anonymous Monk on Jun 05, 2015 at 15:35 UTC

      It might be or may be not considered off topic, may be return function in the perl that I write above is not returning the format understandable by AJS, so I am not sure. I am still figuring it out whats wrong with the code :(

        Then maybe look at what the Perl code returns and see whether it is what you expect?

        The AngularJS documentation should be clear about what it expects.

        With HTTP, you can conveniently test the server side and the client side separately, and even inspect all communication between the two parts. Replace the AngularJS by manual interaction and you can test out the Perl code. Once you are satisfied that your Perl code works as it should, you can then use static files served from your webserver as responses to test your AngularJS code. It's not hard.

        may be return function in the perl that I write above is not returning the format understandable by AJS, so I am not sure.

        What format is it supposed to return?

        Like corion said, try it out to see what it actually returns, then adjust until it matches your expectations

Re: Perl Restfull call by Angular JS not working
by Laurent_R (Canon) on Jun 05, 2015 at 15:42 UTC
    Maybe a question for an AngularJS forum?