Hi Now My AJS code is working fine now. Now the problem is with the perl. Below is code for AJS

<!DOCTYPE html> <html ng-app="MyApp"> <head> <script data-require="angular.js@*" data-semver="1.4.0-rc.2" src=" +https://code.angularjs.org/1.4.0-rc.2/angular.js"></script> <link rel="stylesheet" href="style.css" /> <script src="script.js"></script> </head> <body ng-controller="MyController"> <h1>Welcome!</h1> <ul> <li ng-repeat="x in names">{{x.Name + ' | ' + x.Country}}</li> </ul> <script> var MyResponse = { "records":{ "2":{"City":"México D.F.","Country":"Mexico","Name":"An +a Trujillo Emparedados y helados"}, "1":{"Name":"Alfreds Futterkiste","Country":"Germany","C +ity":"Berlin"} } } var app = angular.module('MyApp', []); app.controller('MyController', ['$scope', '$http', function($sco +pe, $http) { $scope.names = {}; $http.get("http://localhost:5000/about") .success(function (response) {$scope.names = response.records; +}) .error(function(err){ $scope.names = MyResponse.records; }); }]); </script> </body> </html>

Now, when I run the url in the browser, I get the {"records": { "2":{"City":"México D.F.","Country":"Mexico","Name":"Ana Trujillo Emparedados y helados"}, "1":{"Name":"Alfreds Futterkiste","Country":"Germany","City":"Berlin"} } } This is same I required for AJS to work but in the dancer logs it gives an error "Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /usr/local/share/perl/5.18.2/Dancer2/Serializer/JSON.pm line 34. in (eval 299) l. 1"

### App.pm Code ###
package TarView::App; use Dancer2; use Dancer::Exception; our $VERSION = '0.1'; set serializer => 'JSON'; get '/' => sub { template 'index'; }; get '/about' => sub { my %hash = ( records => { 1 => { Name => "Alfreds Futterkiste", City => "Berlin", Country => "Germany" }, 2 => { Name => "Ana Trujillo Empared +ados y helados", City => "México D.F.", Country => "Mexico" } } ); return \%hash; }; true;

As I understand '/' failed to return the JSON which is true because I don't want to return JSON from '/' it should use 'template index'. Can anybody suggest how to accomplish this ?


In reply to Re^4: Perl Restfull call by Angular JS not working by akuk
in thread Perl Restfull call by Angular JS not working by akuk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.