How to Get JSON Data from PHP Script using Angularjs Ajax

How to Get JSON Data from PHP Script using Angularjs Ajax

In this Post We Will Explain About is How to Get JSON Data from PHP Script using Angularjs Ajax With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to GET json data from a php file for an Angular scope Example

In this post we will show you Best way to implement how to get data from mysql database using angularjs, hear for Ajax with AngularJS and PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :   Angularjs find alternative rows in a table using even and odd selector




Getting Started for Ajax with AngularJS and PHP

We have used CDN(libes) for AngularJS so you must need Your internet Data connection for them to work on Read Data from JSON in AngularJS Fetch/Retrieve.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

index.html

This is the main HTML view of our Simple Web Application. In here, we have init Base declared all our simple my this Example(Ajax with AngularJS and PHP) dependencies and the HTML Elements that we have created.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Ajax with AngularJS and PHP</title>
<link rel="stylesheet" href="css/style.css"/>
</head>
<body ng-app="live24uApp">
 <div ng-controller="livepostCtrl">
   <ul>
     <li ng-repeat="article in articlelist">
       <a href="#">{{article.name}}</a>
     </li>
   </ul>
 </div>
</body>
   <script src="live24u/js/jquery-1.10.2.js"></script>
   <script src="live24u/js/controllers.js"></script>
</html>

controllers.js

This contains our simple custom controllers.js files Add Like as javascript, Angularjs scripts

Also Read :   Angularjs Http Introduction-Angular Http post and Get Method Example

live24uApp.controller('livepostCtrl', ['$scope', '$http', function ($scope, $http) {
    $http.get('article.php')
    .success(function(data) {
        $scope.articlelist = data;
    });
}]);

article.php:

Last step, we have add the Following PHP serever side scripts for our simple Angular Ajax Call to PHP Script with JSON return and our Custom Database include.

<?php
require_once("databaseconfig.php");

$liveres = pg_query($dbconn, "SELECT * FROM article ORDER BY name ASC");

header('Content-Type: application/json');
echo json_encode(pg_fetch_assoc($liveres));

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example





Example

I hope you have Got What is Read Data from JSON in AngularJS Fetch/Retrieve And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.