I'm working with Ionic framework and AngularJS. I want to retrieve data from Mysql and decode to JSON using PHP so that I can use it in my Ionic App.
Here is my PHP code
<?php
/*
Here was my php codes to get all data from mysql and assign it to $episode array
*/
header('Content-Type: text/javascript; charset=utf8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Max-Age: 3628800');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
echo json_encode($episode);
//close the db connection
mysqli_close($connection);
When I run my App in the browser The console gave me this error
XMLHttpRequest cannot load http://***Here Was My Url***/episodes.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
The code for controller
$scope.posts = [];
var Url = "http://here was my url/episodes.php";
$http.get(Url)
.success(function(response){
console.log("Reveived getPosts via HTTP: ", response, status);
angular.forEach(response, function(child){
$scope.posts.push(child);
});
})
.error(function(response, status){
console.log("Error while received response. " + status + response);
});
But when I run the App in a real device the array gave me this https://i.stack.imgur.com/b12vC.png
Hope you can help me to solve it.