2011-07-17 1 views
0

vimeo에서 xml 피드를로드해야합니다. 다음과 같이 jquery를 사용하고 있습니다.jQuery를 사용하여 다른 도메인에서 XML 피드를로드하는 중 XMLHttpRequest 오류를 수정하는 방법?

$(function(){ 

// Get vimeo feed 
$.ajax({ 
    type: "GET", 
    url: "http://vimeo.com/api/v2/<my username>/videos.xml", 
    dataType: "xml", 
    success: function(xml) { 
     $(xml).find("video").each(function() { 
      console.log($(this).find("title")); 
     }); 
    } 
}); 

}); 

하지만이 오류가 발생합니다. XMLHttpRequest는 http://vimeo.com/api/v2/ /videos.xml을로드 할 수 없습니다. Origin http://localhost:8888은 Access-Control-Allow-Origin에서 허용되지 않습니다.

차이가 있다면 MAMP를 사용하고 있습니다.

+1

([동일 출처 정책을 우회하는 방법]의 중복 가능성 http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same- origin-policy) – redsquare

답변

1

http://vimeo.com/api/v2/ /videos.json

같은 요청을 vimeo API - User

Making the URL

http://vimeo.com/api/v2/username/request.output
username Either the shortcut URL or ID of the user, an email address will NOT work.
request The data you want. The different request types are listed below.
output Specify the output type. We currently offer JSON, PHP and XML formats.

을 읽을 그래서 대신 http://vimeo.com/api/v2//videos.xml 같은 요청을하시기 바랍니다

이제 $.getJSON을 사용하면 이와 같은 결과를 얻을 수 있습니다.

$(document).ready(function() { 
    var url = "http://vimeo.com/api/v2/{username}/videos.json?callback=?"; 
    $.getJSON(url, function(data) { 
     var items = []; 
     $.each(data, function(key, datum) { 
      items.push("<ul>"); 
      items.push("<li>Title: " + datum.title + "</li>"); 
      items.push("<li>Tags: " + datum.tags + "</li>"); 
      items.push("</ul>"); 
     }); 
     $("#result").html(items.join("")); 
    }); 
}); 

데모보기 : http://jsfiddle.net/naveen/Ssdjp/1/

+0

코드 스 니펫이 많은 도움을 주셔서 감사합니다. JSON 비트에 대해 읽었습니다. –

관련 문제