Sun_china

交流更多,收获更多?

博客园 首页 新随笔 联系 订阅 管理
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title></title>

  <script language="javascript">
function makeRequest(url)
{
if(window.XMLHttpRequest)
{ request = new XMLHttpRequest();}
else
if(window.ActiveXObject)
{ request = new ActiveXObject("MSXML2.XMLHTTP.5.0");}
request.onreadystatechange = onResponse;
request.open("POST", url, false);
request.setRequestHeader('content-type','application/x-www-form-urlencoded');
request.send("a=1&b=2");

}


function onResponse()
{
var obj=request;
if(obj.readyState == 0)
{ document.getElementById('copy').innerHTML = "Sending Request...";}
if(obj.readyState == 1)
{ document.getElementById('copy').innerHTML = "Loading Response...";}
if(obj.readyState == 2)
{ document.getElementById('copy').innerHTML = "Response Loaded...";}
if(obj.readyState == 3)
{ document.getElementById('copy').innerHTML = "Response Ready...";}
if(obj.readyState == 4){
if(obj.status == 200)
{
var response = obj.responseText;
document.getElementById('copy').innerHTML = response;
}
else if(obj.status == 404)
{
// 添加一个定制消息或把用户重定向到另外一个页面
document.getElementById('copy').innerHTML = "File not found";
}
else
{document.getElementById('copy').innerHTML = "There was a problem retrieving the XML."; }
}


}
  </script>
 </head>
 <body onload="makeRequest('WebForm2.aspx');">
  <div id="copy"></div>
 </body>
</html>

注意这里是用post的方法,一定要写post头的,以指明post文档类型,用get方法是a.aspx?id=1&jj=4这样用的
目标文件用request就可以收了


posted on 2007-05-29 16:30  Sun_china  阅读(240)  评论(0编辑  收藏  举报