There was a problem with JSON output using a function. I need something like this:

```
function loadnames()
{
    return $.ajax({
        type: "GET",
        url: "<?php echo $servers; ?>",
        dataType: 'json',
        async: false,
        success: function() {
            console.log('All right');
        },
        error: function () {
            console.log('Cry baby');
        }
    }).responseText;
}

function srvName(sid) {
    var names = JSON.parse(loadnames());
    $.each(names.data.servers, function(index, server) {
        if(server.id == sid) {
            return server.hostname;
        }
    }); 
}

alert(srvName(86));

```

But it does not work. If you remove the sid from the function and put it manually, then everything works and displays what you need ... How to fix this thing?

This works:

```
function srvName() {
    var names = JSON.parse(loadnames());
    $.each(names.data.servers, function(index, server) {
        if(server.id == 86) {
            return server.hostname;
        }
    }); 
}

alert(srvName());
//returns SERVER NAME 86 from alert

```

Json example:

```
{
  "data": {
    "servers":[
        {
            "id":86,
            "hostname":"SERVER NAME 86"
            },
            {
            "id":23,
            "hostname":"SERVER NAME 23"
        }
      ]
    }
}

```