我是javascript的新手,我构建了一个脚本,该脚本从bitstamp API获取最新的比特币价格,此后,回调函数发送参数并将其放在会话中(以便以后可以调用)。
我想知道我做的事是不是一件好事,或者我可以通过一些好的解释使其变得更好。
**我需要像4次一样调用API链接(每次获取其他加密货币价格(LTC,ETH,BCH)。
当我为ETH调用APIV2时出现错误
var HttpClient = function() {
this.get = function(aUrl,aCallback , sign){
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.open("GET",aUrl,true);
anHttpRequest.onreadystatechange = function() {
if(anHttpRequest.readyState == 4 && anHttpRequest.status == 200)
{
var resp = eval("(" + anHttpRequest.responseText + ")");
aCallback(resp,sign);
}
}
anHttpRequest.send( null );
}
}
function cb(response,sign){
var v1 = JSON.parse(response).last; // last value;
var xhttp = new XMLHttpRequest();
xhttp.open("GET","TESTING?"+sign+"=" + v1,true);
xhttp.send();
}
/*var theurl = 'https://www.bitstamp.net/api/ticker';
var client = new HttpClient();
var sign1 = "BTC";
client.get(theurl,cb ,sign1);*/
var theurl2 = 'http://www.bitstamp.net/api/v2/ticker/ethusd';
var client2 = new HttpClient();
var sign2 = "ETH";
client2.get(theurl2,cb ,sign2);
此网址var theurl2 = 'http://www.bitstamp.net/api/v2/ticker/ethusd';
调用时给我一个错误-Failed to load https://www.bitstamp.net/api/v2/ticker/ethusd: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.