1

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?

Baki Kocak
  • 389
  • 1
  • 9

1 Answers1

1

This are the things which are wrong with your code:

  • You are missing a ; in line 2
  • Your function should get the called name, that should look like this: function get_url($url) { ...
  • You have to give a url to the curl_init with curl_init($url)
  • In the line with the return you wrote response, it has to be $response
  • When you are returning a json you should set the header as well with 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.

Community
  • 1
  • 1
Friedrich
  • 2,211
  • 20
  • 42
  • Thanks for comment. Those are miswritten (missing ; and $). I ve edited them.Also added the header in php file but nothing changed.Thanks again. – Baki Kocak Aug 18 '14 at 11:03
  • can you show me the new code? where have you added the header, have you changed the function as well? is error reporting turned on? – Friedrich Aug 18 '14 at 11:25
  • Just edited my post. Interestingly it works on localhost but does not work on smart tv emulator which works as virtual machine in virtualbox.Do you have any idea about it? – Baki Kocak Aug 18 '14 at 11:40
  • propably because the virtual machine has no internet access – Friedrich Aug 18 '14 at 12:04