我有一个这样的变量文件。如何获取JSON数据并存储到变量中。
var geography = [
{ id:"Country", header:"", width:150},
{ id:"Capital", header:"Capital", width:150},
{ id:"Falg", header:"Falg", width:150},
{ id:"Language", header:"Language", width:150},
{id:"Population", header:"Population", width:150},
],
现在我想从json加载这些数据。我将这些数据放入JSON文件并使用此代码。
getGeography function(){
var geography;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "data.json",true);
}
现在从这里如何存储到一个变量并返回。
使用[onreadystatechange的(https://开头developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/onreadystatechange)ie'xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200)geography = xmlhttp.responseText; } };' – Satpal