I've an jQuery JSON request, that loads some JSON from another server (ex. foo.com):

$.getJSON("http://foo.com/json.php",function(data) { alert(data); });

However I receive data as null. This isn't mix-domain problem, I attempted following:

$.getJSON("http://twitter.com/users/usejquery.json?callback=?",
    function(data) { alert(data); });

and received nice JSON object. So, I believe there's trouble with after sales, Apache 2.2.14. Listed here are HTTP headers, sent from server:

Date: Sun, 07 Mar 2010 16:08:38 GMT
Server: Apache/2.2.14 (CentOS)
X-Powered-By: PHP/5.3.1
Content-Length: 2
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8

The headers are identical in each situation: regular HTTP-request or AJAX. However I receive empty quite happy with AJAX, and normal JSON with browser request. I am using Firebug for tests, PHP5 for developing JSON.

Somebody have ideas? Thanks!

I am confident that to be able to do mix domain calls such as this you need a callback, it's the needs to complete JSONP.

here's more information on jsonp http://world wide web.insideria.com/2009/03/what-in-the-heck-is-jsonp-and.html

For jsonp to operate you need a callback for that server to wrap the json string in. for instance:

$.getJSON("http://foo.com/json.php?callback=?", function(data){});

here a callback function is produced by jquery and passed in to the request, so it might be something similar to:

http://foo.com/json.php?callback=generatedFunction

then what's came back through the server ought to be:

generatedFunction("{key:value, key2:value2}");

in which the parameter for the reason that function may be the actual json string.

within the php to come back this it might be something similar to:

$callback = $_GET['callback'];
print($callback."(".json_encode($theobject).");");

Much more about mix-domain JSON throw JSONP and jQuery.