ajax - Requested Json parse failed from a php file -
i trying make application lg smart tv. in index.html, trying json website.
this how call json located in website: (note 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, code below trying parse json using ajax:
$.ajax({ type:"get" ,datatype: 'json' ,url: 'test.php' ,success: function(jsondata){ //things } });
the other thing when try run code in localhost using xampp there no problem, mean code works when comes compiling in lg ide getting requested json parse error. problem?
this things wrong code:
- you missing
;
in line 2 - your function should called name, should this:
function get_url($url) { ...
- you have give url curl_init
curl_init($url)
- in line return wrote
response
, has$response
- when returning json should set header
header("content-type: application/json; charset=utf-8");
i hope thats all. post errors better support. see here how show them.
Comments
Post a Comment