user4547457
user4547457

Reputation:

Getting certain items with get

Sorry if my title is a little confusing I don't know really how to explain it.

API: http://mcping.net/api/162.223.8.210:25567

So I have this code that goes to an API, and I only want it to get the 'variables' online, and max. How would I do this?

Code:

$.get('http://mcping.net/api/162.223.8.210:25567', function(data){
        $.each(data, function(index, item){
            console.log(index + "  ;  " + item)
        });
});

Upvotes: 1

Views: 53

Answers (1)

Eric Martinez
Eric Martinez

Reputation: 31787

Try this

$.get('http://mcping.net/api/162.223.8.210:25567', function(data){
    console.log(data.online);
    console.log(data.max);
});

If your data is already a Javascript object, so you can call its variables properties like in the snippet code.

Just in case I tested it in this fiddle http://jsfiddle.net/js18ykj1/

Upvotes: 3

Related Questions