我学习JavaScript和我有一些问题的功能召回...JavaScript方法调用和打印
这些是我的两个功能: 第一:
function geisson() {
var iabile = new XMLHttpRequest();
iabile.onreadystatechange = function() {
if (iabile.readyState == 4) {
var objectjson = {};
var arrayCards = []; //creazione dell'array che conterrà le cards
objectson = JSON.parse(iabile.responseText);
arrayCards = objectson.cards;
var Ettore = []; //Vèttore di cards
//the results
for (i = 0; i < arrayCards.length; i++)
document.getElementById('image').src = "http://www.mysite.com/png/public/card/" + arrayCards[i].__guid__ + "?width=292";
}
}
iabile.open("GET", "gnekcard.json", true);
iabile.send(null);
}
和第二功能:
function Entity() {
var iabile = new XMLHttpRequest();
iabile.onreadystatechange = function() {
if (iabile.readyState == 4) {
var objectjson = {};
var arrayCards = []; //creazione dell'array che conterrà le cards
objectson = JSON.parse(iabile.responseText);
arrayCards = objectson.cards;
//the results
for (i = 0; i < arrayCards.length; i++)
document.getElementById('informazioni').innerHTML += "\r\n" + "Nome : " + arrayCards[i].__title__ + "\r\n" + "Vanity url: " + arrayCards[i].vanity_urls[0] + "\r\n";
}
}
iabile.open("GET", "gnek.json", true);
iabile.send(null);
}
我想有第三功能,打印的其他2个函数的结果。我宁愿只在第三个函数中拥有“for”,并回想其他方法的向量,但它们不是全局的。我不想有全局变量(如果可能的话),那我该怎么做呢?