如题所述
第1个回答 2014-10-20
<script language="javascript">
function getjson(){
var xmlReq ;
try{
xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
var web = "1.json";//json文件路径
//异步方式
xmlReq.open("GET",web,true);
xmlReq.onreadystatechange = function(){
if (xmlReq.readystate == 4){
document.write(xmlReq.responseText);//对json的文件的操作
}
}
xmlReq.send();
catch(e){
alert(e);
}
}
</script>
参考追问
function getjson(){
var xmlReq ;
try{
xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
var web = "1.json";//json文件路径
//异步方式
xmlReq.open("GET",web,true);
xmlReq.onreadystatechange = function(){
if (xmlReq.readystate == 4){
document.write(xmlReq.responseText);//对json的文件的操作
}
}
xmlReq.send();
catch(e){
alert(e);
}
}
</script>
参考追问
运行之后没反应 需要导入什么文件么?
追答控制台中有没有输出请求到的内容呢?
if (xmlReq.readystate == 4){
//这中间要写你要对json文件的操作
}