I'm using codeigniter and I have some cURL script in my controller, which will get some big json data and loading of it take about 15-20 seconds.
My view is loading so long like the curl time (15-20s).
How to first load my view with some "loading icon", and after script will download all json data replace "loading icon" with my data?
My code:
View:
<?php foreach ($items as $item): ?>
<div class="item-slot">
<img src="http://cdn.steamcommunity.com/economy/image/<?= $item['icon_url'] ?>">
<p><?= $item['name'] ?></p>
</div>
<?php endforeach; ?>
Controller (open_inventory function):
public function open_inventory($steam_id, $appid = 730, $contextid = 2)
{
$data = array("steamid" => $steam_id, "appid" => $appid);
$data_string = json_encode($data);
$ch = curl_init('http://localhost:3000/inventory');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$json = json_decode(curl_exec($ch),true);
if($json['data'])
{
return $json['data'];
}
return false;
}
$items
in View is $json['data']
from Controller.
Regards.