ajax手写代码实现
<script type = "text/javascript">
var xmlhttp = null;
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch(e)
{
alert("xmlhttp创建失败");
}
}
function state_Change()
{
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
var mes = xmlhttp.responseText;
document.getElementById("t1").innerText=mes;
}
}
}
function GetMes()
{
//异步
xmlhttp.open("POST" ,"Default.aspx",true);
xmlhttp.onreadystatechange=state_Change;
xmlhttp.send(null);
//同步
xmlhttp.open("POST","Default.aspx",false);
xmlhttp.send(null);
var mes = xmlhttp.responseText;
document.getElementById("t1").innerText=mes;
setTimeout(GetMes,1000);
}
GetMes();
</script>
var xmlhttp = null;
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch(e)
{
alert("xmlhttp创建失败");
}
}
function state_Change()
{
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
var mes = xmlhttp.responseText;
document.getElementById("t1").innerText=mes;
}
}
}
function GetMes()
{
//异步
xmlhttp.open("POST" ,"Default.aspx",true);
xmlhttp.onreadystatechange=state_Change;
xmlhttp.send(null);
//同步
xmlhttp.open("POST","Default.aspx",false);
xmlhttp.send(null);
var mes = xmlhttp.responseText;
document.getElementById("t1").innerText=mes;
setTimeout(GetMes,1000);
}
GetMes();
</script>