[英]HTML/Javascript- get data from raw pastebin
我有一個網頁,我只需要獲取指定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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.