0
我有一個網頁,我需要獲取指定pastebin文件的原始數據,我們只需說http://pastebin.com/qnNPx6G9,並將其作爲變量存儲。我已經嘗試了xml和ajax請求中的許多變體,但沒有任何效果。這是我嘗試過的。我究竟做錯了什麼?HTML/Javascript-從原始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。
AJAX不能越過domain.so你不能在不同的域名網站使用AJAX。 –
與這個問題無關,但在調試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-引擎收錄-COM-RAW-PHP) – nicholas79171