views:

64

answers:

4

hey, if i try this code

$(document).ready(function(){
    $.ajax({
        url: "http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2",
        type: "GET",
        success: function(msg){
            console.log(msg);
        }
    });
});

i get this error "XMLHttpRequest cannot load http://gdata.youtube.com/feeds/api/users/zdf/playlists?v=2"

How can i make crossdomain ajax calls to get the xml from the api?

+4  A: 

You cannot make a crossdomain call to to get XML. Your only choice to receive data crossdomain is JSON-P.

The same origin policy restricts direct access to a foreign domain (ajax/iframes), json-p uses dynamic script tag insertion to workaround this issue.

Have a look at http://api.jquery.com/jQuery.getJSON/. JSON-P is also covered there.

edit

http://code.google.com/intl/de-DE/apis/youtube/2.0/developers_guide_json.html

Made for you!

jAndy
thank you!!!!!!
antpaw
@antpaw: welcome. damn, your website freezed my chrome :P
jAndy
@jAndy: you need at least a deze core cpu!
antpaw
+1  A: 

There is an ongoing standardization process to work out a scheme to allow cross-domain ajax requests JSON-P is just a temporary workaround since it uses the script tag to make HTTP requests, which is inferior to the XMLHttpRequest object.

The proposed solution is based on letting the resource origin specify which domains that are allowed to make cross-domain requests, the domain "*" means that any other web page can host an application that makes requests to that specific resource.

You can read more in the w3c Working draft

This is supported in modern web-browsers.

Ernelli
A: 

try $.load() . see http://api.jquery.com/load/

Florin P.
A: 

You have some options here, as it was said you can use JSONP, but I usually use PHP proxy script that fetches remote data and sends it back as an AJAX callback.

Tomasz Kowalczyk