此代码均写在 script中,仅供参考!!!!
//定义入口函数
window.onload=function(){
//创建ajax引擎对象
var xmlHttp=new XMLHttpRequest();
//绑定监听事件
xmlHttp.onreadystatechange=funtion(){
//判断网络状态码,获取服务器返回结果
if(xmlHttp.readyState==4&&xmlHttp.status==200){
//获取网络请求结果
var text=xmlHttp.responseText;
//弹出对话框提示响应内容
alert(text);
}
}
//绑定请求url
/*
*method:string,url:string,async?
* method:请求方式:post get
* url:后台请求路径
* async:boolean:true或者false true代表异步请求,false代表同步请求*
*/
xmlHttp.open("GET","http://www.baidu.com",true);
//发送请求
xmlHttp.send();
}