我有一个网页,我需要在其中获取指定的pastebin文件的原始数据,让我们只说http://pastebin.com/qnNPx6G9,并将其存储为变量。我在xml和ajax请求上尝试了很多很多变种,但没有任何作用。这是我尝试过的。我做错了什么?
我尝试过使用Ajax:
int
使用常规XMLHttpRequest:
$.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.
请帮忙!我很抱歉,如果这是一个愚蠢的问题,或者任何事情都不清楚,我在理解API时并不擅长。谢谢!
不,我不能使用PHP。
答案 0 :(得分:0)
您正在尝试发出一个明确不允许的pastebin请求,因为控制台显示此错误:
请求时没有'Access-Control-Allow-Origin'标头 资源。
我认为您唯一的选择是使用服务器端编程语言来远程访问pastebin,只有在远程服务器授权的情况下才允许CORS请求,否则您无法绕过它。 / p>
详细了解CORS here