Tuesday, 18 April 2017

How to fetch json data from url using angularjs?

I am new in angular js. I have to fetch json data from url using angular i am using node.js as my server side.

by using php it is working Here is my php code

<?php

$json = file_get_contents('online url');
$obj = json_decode($json);
print("<pre>");
print_r($obj);

?>

but the same url is not working by using angular js here is the code

$http.get('online url')
                .success(function(data) {
                    $scope.names = eval(data);
                    console.log(data)
                })
                .error(function(data) {
                    alert(data);
                    console.log('Error: ' + data);
                });


            }

Please help me to find out the solution?



via Athi

No comments:

Post a Comment