I'm trying to use AJAX to call a function in a PHP file.

The function basically takes data that is submitted in the AJAX call, makes a couple other requests to API's, and gets a JSON object from an external API.

I want to send that JSON object back to my page, to be acted on by javascript.

Here is my code:

```
function secureGet(sumNam){

    $.ajax({
        dataType: "json",
        type: 'POST',
        data: {sumNam: sumNam},
        url: 'get_score.php',
        success: function (json, state) {
            console.log(state);
            statsObject = json;
            console.log(statsObject);
        }
    })
}

```

**PHP:**

```
    <?php
require_once 'apikey.php';

if(isset($_POST['sumNam'])){
$name = $_POST['sumNam'];
secureProxy($name);
}

function secureProxy($summoner_name){

$url_one = "https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/" . $summoner_name . "?api_key=" . $api_key;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, $url_one);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result_one = curl_exec($ch);
    curl_close($ch);

$json_array = json_decode($result_one, true);

$summoner_id = $json_array[$summoner_name]['id'];

$url_two = "https://na.api.pvp.net/api/lol/na/v2.2/matchhistory/" . $summoner_id .  "?rankedQueues=RANKED_SOLO_5x5,RANKED_TEAM_5x5&beginIndex=0&endIndex=10&api_key=" . $api_key;

    $ch2 = curl_init();
    curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch2, CURLOPT_URL, $url_two);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    $result_two = curl_exec($ch2);
    curl_close($ch2);

print_r($result_two);

}

?>

```

I think the call is successfully being made because in my console it says:

```
iGET XHR  http://127.0.0.1/b2p/get_score.php [HTTP/1.1 200 OK 1551ms]

```

But the console isn't logging any information on the returned object.

Any reason as to why this might be happening?

Thanks!

```
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: api_key in C:\wamp\www\b2p\get_score.php on line <i>12</i>

```

...this goes on for a while

```
{"status": {"message": "Missing api key", "status_code": 401}}

```

But the API call works when I do it on its own.