jquery - display json file in html with php ajax or php -
hey guys if have gotten json file webservice best way display in html. should utilize php display content or ajax. if php how that.
this sample of json file
{ "results": [ { "title": "brick mansions", "released": "2014", "restricted": "12 \u00e1ra", "imdb": "6.0\/10 5,532 atkv.", "imdblink": "http:\/\/www.imdb.com\/title\/tt1430612", "image": "http:\/\/kvikmyndir.is\/images\/poster\/9260_500.jpg", "showtimes": [ { "theater": "laugar\u00e1sb\u00ed\u00f3", "schedule": [ "20:00", "22:00" ] } ] }, { "title": "how train dragon 2", the contents in array called $movies can see in php file
<?php $service_url ='http://apis.is/cinema'; $curl = curl_init($service_url); curl_setopt($curl, curlopt_returntransfer, true); $curl_response = curl_exec($curl); if ($curl_response === false) { $info = curl_getinfo($curl); die('error occured during curl exec:'. var_export($info)); } curl_close($curl); //get file , insert json file $movies = json_encode(json_decode($curl_response), json_pretty_print); file_put_contents('json/data.json', $movies); ?> i've been trying set in index.php page , without luck. problably ease i'm new in backend.
this index.php file
<body> <?php include 'php/response.php';?> <?php echo "$movies"; ?> <div class="container"> <div class="movies" style="background-color:green;"> <?php if (is_array($movies)): ?> <?php foreach($movies $movie): ?> <?php echo $movie['title']; ?> <?php endforeach ?> <?php endif; ?> </div> </div> as can see array $movie prints on page cant seem print title , on. in advanced.
try converting json file php can understand i.e array.
also there no need wrap each php line in <?php.. ?> if have more 1 line of code utilize 1 time turn on interpreter , 1 time turn off. create code much more easy read , debug.
<body> <?php include 'php/response.php';?> <?php echo "$movies"; // echos text string $movys = json_decode($movies); // convert json string object ?> <div class="container"> <div class="movies" style="background-color:green;"> <?php if (is_array($movys->results)): foreach($movys->results $movie): echo $movie->title; endforeach; endif; ?> </div> </div> php jquery ajax json
No comments:
Post a Comment