越简单越好!

JavaScript 模拟 POST

发表于 2007-03-13 09:04 | 1028次阅读 0次点赞   JavaScript

<script language="JavaScript">
<!--
var xmlHttp;
var url = 'a.php';
function createxmlHttpRequest(){
if (window.xmlHttpRequest) { // Mozilla, Safari, ... 
xmlHttp = new xmlHttpRequest();
} else if (window.ActiveXObject) { // IE
xmlHttp = new ActiveXObject("Microsoft.xmlHttp");
}
return xmlHttp;
}
xmlHttp = createxmlHttpRequest();

function loadnews(){
xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState==4){
     if (xmlHttp.status==200){
      if(xmlHttp.responseText!=""){    
       alert(xmlHttp.responseText);
      }
     }
}
//alert(xmlHttp.status);
}
xmlHttp.open("post",url,true);

xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
xmlHttp.send('a=1');
}
loadnews();
//-->
</script>

返回顶部 ^