반응형
교차 도메인 jquery get
아약스를 사용한 크로스 도메인의 예를 몇 가지 보았지만 작동하지 않습니다.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<script type="text/javascript" >
$(document).ready(function () {
var url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=AssasNet&include_rts=1";
$.get(url, function (data) {
console.log(data)
alert(data);
});
});
</script>
</body>
</html>
크롬을 사용해보니 다음과 같은 오류가 발생합니다.
XMLHttpRequest cannot load http://api.twitter.com/1/statuses/user_timeline.json?screen_name=AssasNet&include_rts=1. Origin null is not allowed by Access-Control-Allow-Origin.
사용할 수 없습니다.$.get왜냐하면 그것은 교차 오리진이고 따라서 동일한 오리진 정책에 의해 차단될 Ajax 호출을 하고, 당신이 액세스하려는 Twitter API는 교차 오리진 리소스 공유를 지원하지 않기 때문입니다(또는 지원한다면, 어느 오리진도 허용하지 않습니다).null또는http://jsbin.com제가 시도한 것입니다.)
그러나 API는 JSONP를 지원하므로(이것은 진정한 아약스 호출이 아닙니다), 단지 변경할 뿐입니다.$.get완전히$.ajax지정JSONP작업:
$.ajax({
url: url,
dataType: "jsonp",
success: function (data) {
console.log(data)
alert(data);
}
});
언급URL : https://stackoverflow.com/questions/15369577/cross-domain-jquery-get
반응형
'programing' 카테고리의 다른 글
| VARCHAR 필드에서 MAX() 사용 (0) | 2023.08.13 |
|---|---|
| 앱 시작 시 "BatchedBridge를 가져올 수 없습니다. 번들이 올바르게 패키지되었는지 확인하십시오." 오류 (0) | 2023.08.13 |
| Oracle DB 버전을 가져오기 위한 쿼리 (0) | 2023.08.13 |
| Springfox Swagger에서 제공하는 Swagger /v2/api-docs에서 CORS 헤더를 활성화하려면 어떻게 해야 합니까? (0) | 2023.08.13 |
| PowerShell에서 문자열을 변수와 연결하려면 어떻게 해야 합니까? (0) | 2023.08.13 |