0
웹 페이지에서 지정한 pastebin 파일의 원시 데이터를 가져와야합니다. 그냥 http://pastebin.com/qnNPx6G9이라고 말하고 변수로 저장하십시오. xml 및 ajax 요청에 많은, 많은, 많은 변형을 시도했지만 아무것도 작동하지 않습니다. 여기 내가 시도한 것이있다. 내가 도대체 뭘 잘못하고있는 겁니까?HTML/자바 스크립트 - 원시 pastebin에서 데이터 가져 오기
나는 Ajax를 시도했다 :
$.ajax({
url: "http://pastebin.com/api/api_post.php",
type: "GET",
dataType: "x-www-form-urlencoded",
data: {
"api_dev_key": "mydevkey",
"api_option": "paste",
"api_paste_code": "blah blah"
},
success: function(res) {
alert(JSON.stringify(res));
},
error: function(res) {
alert(JSON.stringify(res));
}
});
//this is in the form of create paste, because I was seeing if it would work where get did not- it didn't.
을 그리고 정기적으로 XMLHttpRequest를 가진 :
var xhr = new XMLHttpRequest();
xhr.open('POST'/*also tried GET*/, 'http://pastebin.com/raw/qnNPx6G9', true); //I've also tried /raw.php?i=qnNPx6G9
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
alert(this.responseText);
}
};
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send("api_option=trends&api_dev_key=DEVKEY");
//I tried trends because creating a paste and getting a paste didn't work.
이 도와주세요! 이것이 어리석은 질문이거나 불분명 한 것이면 미안합니다. API를 잘 이해하지 못합니다. 감사!
아니요, 저는 PHP를 사용할 수 없습니다.
아약스 CORS에 대해 자세히 알아보십시오. –
질문과 관련이 없지만 JSON을 경고하는 대신 디버깅 할 때 [console.log'] (https://developer.mozilla.org/en/docs/Web/API/Console/log)를 반드시 확인해야합니다. 브라우저 devtools도 좀 더 유용한 정보를 표시 할 수 있습니다 :) – Scott
가능한 [JQuery Ajax 요청의 중복 http://pastebin.com/raw.php] (http://stackoverflow.com/questions/16449492/jquery-ajax-request -to-http-pastebin-com-raw-php) – nicholas79171