0

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;
}
6
  • The search keyword you are looking for is "Ajax" (assuming you mean client side JS in a web page) Commented Jun 28, 2014 at 14:19
  • You make an XHR request. There's copious information online describing how to do this. Commented Jun 28, 2014 at 14:22
  • I have already tried all of that stuff, its not working. Commented Jun 28, 2014 at 14:31
  • 1
    That's a cross domain call which you can only perform if the remote server allows it which that one does not. Try jsonp. Commented Jun 28, 2014 at 15:02
  • 1
    Thanks Alex, the problem was that i was using json instead of jsonp. Commented Jun 28, 2014 at 15:37

1 Answer 1

1

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));
        }

    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.