Question: I have the following jquery code:

```
$(document).ready(function() 
{
    $('button').click(function() 
    {
        $.getJSON('http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/server/status?output=json', function(json)
        {
            alert("Entered getJSON");

            $("#output").append("working...");            
            if(json.status.indexOf("success")===0)
            {
                alert("success");
                $.each(json.results, function(i, data) 
                {
                    $("#output").append(data.text);
                });
            }else
            {
                alert("Failed to load url");
            }
        });
    });
});

```

The json that is pulled from the url looks like:

```
{"worldServerStatus": {
 "customMessage": "",
 "lastChangedDate":  {
  "date": 31,
  "day": 4,
  "hours": 17,
  "minutes": 48,
  "month": 4,
  "nanos": 0,
  "seconds": 32,
  "time": 1338486512000,
  "timezoneOffset": 0,
  "year": 112
 },
 "localizedMessage": "The servers are currently up and running.",
 "message": "ALL_SYSTEMS_GO",
 "status": "UP"
}}

```

My jquery just refuses to enter the $.getJSON function, the "enetered getJSON" alert doesn't fire.

What is wrong?

Solved. Thank you all :)

Answer: 
You can not fetch JSON from another domain unless they support [CORS](https://developer.mozilla.org/en/http_access_control) because of the [same origin policy](https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript). 

Does the api support [jsonp](http://api.jquery.com/jQuery.getJSON/#jsonp)?
I don't think you will be able to do this. For cross domain ajax requests the api provider have to use jsonp. What you can do is create a php file for the request. Lets call the file request.php 

```
<?php   
/* gets the data from a URL */
function get_data($url)
{
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

$query = $_SERVER['QUERY_STRING'];
$url = ('http://world.needforspeed.com/SpeedAPI/ws/game/nfsw/server/status?'.$query);

echo get_data($url);

?>

```

Then in your javascript

```
$.getJSON('http://myserver.com/request.php?output=json', function(json) 

```