Reputation: 388
I am trying to make an application for LG Smart TV. In index.html, trying to get an json from a website.
This is how i call the json located in my website: (note that it is called test.php in LG ide)
<?php
header("Content-type:application/json; charset=utf-8");
echo get_url("http://website.com/proxy/collection.php?format=json&main_category_id=2");
function get_url($request_url){
$ch=curl_init($request_url);
curl_setopt($ch,CURLOPT_URL, $request_url);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?>
and in index.html, the code below trying to parse json using ajax:
$.ajax({
type:"get"
,dataType: 'json'
,url: 'test.php'
,success: function(jsonData){
//things to do
}
});
The other thing is that when i try to run this code in localhost using xampp there is no problem, i mean the code perfectly works but when it comes to compiling in LG IDE I am getting requested JSON parse error. What could be the problem?
Upvotes: 1
Views: 874
Reputation: 2300
This are the things which are wrong with your code:
;
in line 2function get_url($url) { ...
curl_init($url)
response
, it has to be $response
header("Content-type: application/json; charset=utf-8");
I hope thats all. You could post the errors as well to get better support. See here how to show them.
Upvotes: 1