XMLHttpRequest函数

时间:2021-10-22 00:21:41

function createXmlHttpRequest(){
if(window.ActiveXObject){
return new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
return new XMLHttpRequest();
}
}
(function(){
var url = "/ordermgr/a.txt";
xmlHttpRequest = createXmlHttpRequest();
xmlHttpRequest.onreadystatechange = goods;
xmlHttpRequest.open("GET",url,true);
xmlHttpRequest.send(null);
})();
function goods(){
if(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){
var data = xmlHttpRequest.responseText;
data = strToJson(data);
dom.innerHTML = $formatTpl(tp.goodsList,{list:data.list})
}
}
function strToJson(str){
var json = (new Function("return " + str))();
return json;
}