我有一个网页,我需要在其中获取指定 pastebin 文件的原始数据,比如说http://pastebin.com/qnNPx6G9,并将其存储为变量。我已经尝试了很多很多关于 xml 和 ajax 请求的变体,但没有任何效果。这是我尝试过的。我究竟做错了什么?
我尝试过使用 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。