2012-11-28 15 views
0

JavaScript를 통해 ORCID API에 액세스하려고합니다. 나는 JSONPfor에게 크로스 도메인 호출을 사용하지만,이 오류가 발생합니다 :잡히지 않은 SyntaxError : 예기치 않은 토큰 <

Uncaught SyntaxError: Unexpected token <

우는 소리가 내가 사용하는 코드입니다 :

<html > 
<head> 
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() 
    { 
$.ajax({ 
     type: 'GET', 
     url:'http://pub.orcid.org/0000-0002-5426-4031/orcid-bio', 
     dataType: 'jsonp' 
     }).done(function(res){alert("sucess")}). 
      fail(function(res){alert("failed"); console.log(res)}). 
      always(function(res){alert("complete")}); 
    }); 
</script> 
</head> 
<body> 
</body> 
</html> 
+0

=> – sdespont

+8

여기에서 사용하는 URL은 JSON이 아닌 XML을 반환합니다. –

+3

서버에서 JSONP를 지원해야합니다. JSONP가 자동으로 발생하지 않는다고 기대하는 jQuery에 대해 알려줍니다. –

답변

2

this page에 따라 명시 적으로 적절한 통해 요청하면 서비스는 JSON을 반환합니다 Accept 헤더.

Accept: application/orcid+json 

이것은 하지 자동 ORCID에서 지원하지 않는 것 JSONP를 가능하게 할 것이다, JSON 출력을 생성하도록 서버를 말할 것이다.

여기에 a request to add JSONP on their support site이 있습니다.

+0

를 JSONP 수락 : 응용 프로그램/orcid + JSON 나는이 '수용'을 사용 $ 아약스 ({ 유형 : 'GET', URL : '에 http : // 술집. orcid.org/0000-0002-5426-4031/orcid-bio ', dataType :'jsonp ', 허용 :'application/orcid + json ' }) 완료 (function (res) {alert ("sucess")}). 실패 (기능 (res) {경고 ("실패"); console.log (res)}). 항상 (function (res) {alert ("complete")}); }}); 요청 헤더가 여전히 이와 같습니다. "수락 : */*" –

관련 문제