ajax.js
来自「很好用得tree。也很简单。里面只有3个文件。」· JavaScript 代码 · 共 73 行
JS
73 行
var req = new function()
{
this.xhr = null;
this.xmldata = null; //xml数据
this.userid = null;
this.createInstance = function()
{
var instance = null;
try
{
instance = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
instance = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E)
{
instance = false;
}
}
if(!instance && typeof XMLHTTPRequest != 'undefined')
{
instance = new XMLHTTPRequest();
if (instance.overrideMimeType)
{
instance.overrideMimeType="text/xml";
}
}
return instance;
}
this.getxmldata= function()
{
this.userid = arguments[0];
xhr = this.createInstance();
xhr.onreadystatechange=this.buildxmltree;
xhr.open("GET","/getdatafromXML?userid="+arguments[0],true);
xhr.send(null);
}
this.buildxmltree = function() //构建tree
{
if(xhr.readyState==4)
{
if(xhr.status==200)
{
req.xmldata = xhr.responseText;
var o = new ActiveXObject('Microsoft.XMLDOM');
o.async = false;
o.loadXML(req.xmldata);
req.doXMLMsg(o);
}
else
{
//deal the error here
}
}
}
this.doXMLMsg = function(obj)
{//解释见treeview.js
treeview.data = obj;
treeview.xhr = req.xhr;
treeview.userid = req.userid;
treeview.init();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?