xmlhttp实例

<script type="text/javascript">
function GetItemText(itemid,vtype)
{
var pstr="";
var itemtext="";
alert(itemid+','+vtype);
if(vtype==1)
{
itemtext=document.getElementById(itemid).value;
pstr="{%localhost%}/"+"?a=1&b=2";
alert(pstr);

}
if(pstr=="") return;
var xmlhttp;

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
str=xmlhttp.responseText;
alert(str);
if (xmlhttp.readyState==4&&xmlhttp.status==200)
{
str=xmlhttp.responseText;
alert(str);
document.getElementById("txtHint").innerHTML=str;

}
}

xmlhttp.abort() ;
xmlhttp.open("GET",pstr,true);
xmlhttp.setRequestHeader("No-Cache","1");
xmlhttp.setRequestHeader("Pragma","no-cache");
xmlhttp.setRequestHeader("Cache-Control","no-cache");
xmlhttp.setRequestHeader("Expire","0");
xmlhttp.setRequestHeader("Last-Modified","Wed, 1 Jan 1997 00:00:00 GMT");
xmlhttp.setRequestHeader("If-Modified-Since","-1");

xmlhttp.send();

}
</script>

posted @ 2014-12-24 22:51  LAOS  阅读(188)  评论(0编辑  收藏  举报