user1176999
user1176999

Reputation: 470

Http GET request in javascript

How can I get JSON from http get request in javascript? The URL is:

    http://www.streamfinder.com/api/?api_codekey=[devkey]&do=get_genre_list&return_data_format=json

I have already tried a lot of stuff, but none of them seem to work... I have tried this, but it is also not working.

function httpGet(theUrl)
{
    var xmlHttp = null;

    xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false );
    xmlHttp.send( null );
    return xmlHttp.responseText;
}

Upvotes: 0

Views: 6046

Answers (1)

user1176999
user1176999

Reputation: 470

The problem was that i was using json instead of jsonp. The code that worked is this:

$.ajax({
        url: "URL",
        type: 'GET',
        dataType: 'jsonp',
        success: function(res) {

            alert(JSON.stringify(res));
        }

    });

Upvotes: 1

Related Questions