I have created a JSON API using PHP for a desktop widget app I am developing, which has has the structure:
{"a":"b"}
The client (in other words the widget) requests the API using $.getJSON and requests the URL
"http://mylink.php?callback=?"
but no results are returned (whereas when I type the same URL directly in the browser, the results are there and correct). I also tried to request another JSON API (not created by me) and it works fine, it returns results. So I am almost sure that the problem is in the way I create my API.
The code for creating the JSON API in the server's side is the following:
<?php
..............
$results = array();
$results['a'] = 'b';
$encoded = json_encode($results);
$encoded_callback = '?' . '(' . $encoded . ')';
echo $encoded_callback;
return $encoded_callback;
?>
The javascript code only contains
$getJSON(url, output, function(...){
......
});
up to now and works fine with another API. I cannot figure out what I am doing wrong, either with the creation of the API from the server or with the URL request from the client. Do you have any ideas?