📄 myajax.js
字号:
var XmlHttp;
var tempDiv;
var curpage;
divs=new Array();
//获取IE版本
function getAjax()
{
try
{
XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try
{
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(oc){
XmlHttp = null;
}
}
if(!XmlHttp && typeof XMLHttpRequest != "undefined")
{
XmlHttp = new XMLHttpRequest();
}
}
//用Get方式提交服务器,并吧返回结果插入到指定Id的层中
function GetBegin(url,Id)
{
if(Id.indexOf(",")==-1){
tempDiv=document.getElementById(Id);
}else{
tempDiv=null;
items=Id.split(",");
for(i=0;i<items.length;i++)
{
its=document.getElementById(items[i]);
divs.unshift(its);
}
}
getAjax();
XmlHttp.onreadystatechange=Getstate;
XmlHttp.open("Get",url,true);
XmlHttp.send(null);
}
//用Get方式提交服务器,没有返回结果
function NullBegin(url)
{
getAjax();
alert(url);
XmlHttp.onreadystatechange=NullState;
XmlHttp.open("Get",url,true);
XmlHttp.send(null);
}
//用Post方式提交服务器,没有返回结果
function PostNullBegin(url,sendcontext)
{
getAjax();
XmlHttp.onreadystatechange=NullState;
XmlHttp.open("Post",url,true);
XmlHttp.send(sendcontext);
}
function NullState()
{
}
//用Get方式提交服务器,并吧返回结果插入到指定Id的层中
function Getstate()
{
if(XmlHttp.readyState==4&&XmlHttp.status==200)
{
if(tempDiv!=null){
tempDiv.innerHTML=XmlHttp.responseText;
}else{
result=XmlHttp.responseText;
rs=result.split(",");
for(i=0;i<rs.length;i++)
{
if(divs[i].tagName=="INPUT")
{
divs[i].value=rs[i];
}else{
divs[i].innerHTML=rs[i];
}
}
}
}
}
//用Post方式提交服务器,并吧返回结果插入到指定Id的层中
function PostBegin(url,Id,sendContext)
{
tempDiv=document.getElementById(Id);
getAjax();
XmlHttp.onreadystatechange=PostState;
XmlHttp.open("Post",url);
XmlHttp.send(sendContext);
}
//用Post方式提交服务器,并吧返回结果插入到指定Id的层中
function PostState()
{
if(XmlHttp.readyState==4&&XmlHttp.status==200)
{
tempDiv.innerHTML=XmlHttp.responseText;
}
}
function GetAddBegin(url,Id,cur)
{
tempDiv=document.getElementById(Id);
curpage=document.getElementById(cur);
getAjax();
XmlHttp.onreadystatechange=AddState;
XmlHttp.open("Get",url,true);
XmlHttp.send(null);
}
function PostAddBegin(url,Id,sendText)
{
tempDiv=document.getElementById(Id);
getAjax();
XmlHttp.onreadystatechange=AddState;
XmlHttp.open("Get",url);
XmlHttp.send(sendText);
}
function AddState()
{
if(XmlHttp.readyState==4&&XmlHttp.status==200)
{
result=XmlHttp.responseText;
i=result.indexOf("<table");
curpage.innerHTML=result.substr(0,i)
tempDiv.innerHTML=result.substr(i);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -