How do I set the php files in angularJS to set the id of any json code?
Hole and sole this is my final code
<!DOCTYPE html>
<html class="no-js" lang="en" ng-app="myBusStopApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>My bus stop - Real time data</title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
<script type="text/javascript">
angular.module('myBusStopApp', [])
.controller('myBusStopCtrl', ['$scope', '$http', function ($scope, $http) {
//$scope.realTimeData;
var url ="http://192.168.1.10/android_connect/JsonReturn.php";
// var url = "http://reis.trafikanten.no/reisrest/realtime/getrealtimedata/3010435" + "?callback=JSON_CALLBACK";
alert(url);
$http.jsonp(url)
.success(function(data){
alert(url);
$scope.realTimeData = data;
});
}]);</script>
</head>
<body style="margin-top:2%;font-size:14px;font-family:Open Sans; padding-left:2%;padding-right:2%;">
<div ng-controller="myBusStopCtrl">
<center>
<div class="table-responsive" style="max-width:800px;">
<table class="table table-striped" >
<thead>
<tr class="info">
<th>Bus#</th>
<th>Destination</th>
<th>Wait time</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in realTimeData">
<td>{{item.id}}</td>
<td>{{item.email}}</td>
<td>kk</td>
</tr>
</tbody>
</table>
</div>
</center>
</div>
</body>
</html>
When I try any other setting, then it causes a chrome error
Resource interpreted as Script but transferred with MIME type text/html
And following is my PHP code
<?php header('Access-Control-Allow-Origin: *'); ?>
<?php
// set up the connection variables
$db_name = 'hotel_db';
$hostname = 'localhost';
$username = 'root';
$password = '';
// connect to the database
$dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
// a query get all the records from the users table
$sql = 'SELECT * FROM user';
// use prepared statements, even if not strictly required is good practice
$stmt = $dbh->prepare( $sql );
// execute the query
$stmt->execute();
// fetch the results into an array
$result = $stmt->fetchAll( PDO::FETCH_ASSOC );
// convert to json
$json = json_encode( $result );
// echo the json string
echo $json;
?>
What can i do in this situation
Please help me of this Thanx in advance
in upeer code i have include this
<?php header('Access-Control-Allow-Origin: *'); ?>
but show me error in chrome but i have run this code in android phone
XMLHttpRequest cannot load http://192.168.1.10/android_connect/JsonReturn.php. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.
Please please help me out of this situation please