Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用带有bitbucket访问令牌的纯javascript/(ajax)来获取JSON数据?_Javascript_Json_Ajax_Bitbucket - Fatal编程技术网

如何使用带有bitbucket访问令牌的纯javascript/(ajax)来获取JSON数据?

如何使用带有bitbucket访问令牌的纯javascript/(ajax)来获取JSON数据?,javascript,json,ajax,bitbucket,Javascript,Json,Ajax,Bitbucket,我不确定如果不使用服务器,它是否会工作,但我确实得到了响应。所以它确实认为这是可能的。以下是我到目前为止所做的尝试,下面是回调站点 <html><head><script> window.onload = function(){ try{ var url = window.location.href.split("#"); var token = url[1]; var xmlhttp = new XMLHttpRequest();

我不确定如果不使用服务器,它是否会工作,但我确实得到了响应。所以它确实认为这是可能的。以下是我到目前为止所做的尝试,下面是回调站点

<html><head><script>
window.onload = function(){
    try{
        var url = window.location.href.split("#"); 
var token = url[1];
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
        try{
        var myObj = JSON.parse(this.responseText);
        document.body.innerHTML = myObj.name;
            alert("worked");
        }catch(e){alert(e);}
  }else{
        document.body.innerText = this.response;
        alert("didn't exactly work");
    }
};
xmlhttp.open("get", "https://bitbucket.org/!api/2.0/user/"+token, true);
xmlhttp.setRequestHeader('Authorization', 'Bearer '+token);
xmlhttp.send();
    }catch(e){alert(e);}
}
</script></head><body>
<iframe id="testframe"></iframe>
</body></html>


window.onload=函数(){
试一试{
var url=window.location.href.split(“#”);
var-token=url[1];
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
试一试{
var myObj=JSON.parse(this.responseText);
document.body.innerHTML=myObj.name;
警惕(“已工作”);
}捕获(e){警报(e);}
}否则{
document.body.innerText=this.response;
警惕(“完全不起作用”);
}
};
open(“get”https://bitbucket.org/!api/2.0/user/“+令牌,true);
setRequestHeader('Authorization'、'Bearer'+令牌);
xmlhttp.send();
}捕获(e){警报(e);}
}
响应是一条错误消息,表示访问令牌已过期,请尝试刷新页面


最终目标是使用Bitbucket API,只使用Bitbucket站点,不运行我自己的服务器。

您看过Bitbucket OAuth的应用程序了吗?特别是“隐式授予”流?我使用通配符将访问令牌发布到另一台服务器(*.000webhost.com),尝试读取JSON对象时获得了成功,但当我将令牌发布到bitbucket上的另一个页面时,我收到消息“此端点不支持基于令牌的身份验证”。