0

I'm trying to fetch some youtube video data, using the jquery api get() and getJSON(), but I got not responses.

$.get('http://gdata.youtube.com/feeds/api/videos/eGfAj9ZJymo',
    function(data) {
        alert('data loaded');
    });

I also try with getJSON function, and I got the same result, none.

but I tested this example http://jsfiddle.net/FzejW/, and did work.

1
  • have you included the jQuery framework in your code? Commented Jan 28, 2011 at 5:05

1 Answer 1

1

If you notice, the jsFiddle example that you gave has a callback=? parameter in its query string. That triggers jQuery to use JSONP instead of JSON.

The reason your code doesn't work is probably due to the same origin policy: You cannot fetch data from another origin (protocol + subdomain + domain + port) using XHR. But you can do JSONP simply because JSONP is done through <script> tags and are not subject to the same origin policy.

http://api.jquery.com/jQuery.getJSON/

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

Try including callback=? in your request URL and see if it helps...

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.