I am trying to display contents retrieved from an external URL using JSON (the cURL method). So i wrote the below function:
function file_get_contents_curl() {
//JSON URL which should be requested
$gry_str = "?timezone=" . urlencode(date_default_timezone_get()) . "&dateFrom=" . date('Y-m-d') . "&dateTill=" . date('Y-m-d');
$json_url = 'https://www.example.com/json/financial-calendar.json' . $gry_str;
// Initializing curl
$ch = curl_init();
//Configuring curl options
$options=array(CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_URL => $json_url);
//Setting curl options
curl_setopt_array($ch, $options);
//Getting resutls
$results= curl_exec($ch); //Getting json result string
}
I want the contents retrieved to be displayed in an HTML table. So i am using this:
<script id="calendarContentTemplate" type="text/html">
<![CDATA[
<tr>
<td class="calendar-local-time"><%= time %></td>
<td class="region"><%= region %></td>
<td class="title"><%= title %></td>
<td><%= forecast %></td>
<td><%= previous %></td>
</tr>
]]>
and my constructed table like this:
<table class="calendar-table">
<thead>
<tr>
<th class="time">Time</th>
<th class="region">Region</th>
<th class="title">Event</th>
<th class="forecast">Forecast</th>
<th class="previous">Previous</th>
</tr>
</thead>
<tbody>
<tr>
<td class="calendar-local-time"></td>
<td class="region"></td>
<td class="title"></td>
<td></td>
</tr>
</tbody>
</table>
Nothing is being displayed on the table. Am I doing something wrong? Or do I need a Drupal function to make it work? Forgot to mention that its for the front page.
I have read about the drupal_json_output() function. But I am not sure if I have to use it. When I tried using it my webpage appeared only HTML.
It is very weird, because when I open Firebug I can see in the Net section. I am receiving Status as 200 Ok for request, but the response is completely empty.
Any help is greatly appreciated.