in reply to Perl and AngularJS - Help Required
You need the response to be
{"records":[{"email":"test@test.com","name":"test"} ..
Try
#!/usr/bin/perl -w use strict; use warnings; use CGI; use DBI; use JSON; my %output=(); my $dbh = DBI->connect("dbi:mysql:database=test","usern","userp") or die "Connecting from Perl to MySQL database failed: $DBI::errstr" +; my $sth = $dbh->prepare('SELECT name, email FROM user_tb'); $sth->execute; while ( my $row = $sth->fetchrow_hashref ){ push @{$output{'records'}}, $row; } my $cgi = CGI->new; print $cgi->header( 'application/json' ); print to_json( \%output );
or leave cgi and change the html. Remove .records and use
$scope.names = response.data;or just change last line of cgi to
print to_json( { 'records' => \@output } ); poj
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl and AngularJS - Help Required
by Anonymous Monk on Jan 08, 2017 at 17:14 UTC |