----------------------原始的ajax:
function guo() {
var xhr
if (XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
xhr = ActiveXObject("XMLHttpRequest");
}
//ie5 和ie6是activeobject;
//请求方式,地址,是否异步;
xhr.open("get", "../Handler/test.ashx", true);
//发送请求
xhr.send();
//readystate:0未初始化;1,已打开,2,已发送,3正在接受,4,已加载
xhr.onreadystatechange = function (data) {
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
};
}
--------post方式
function guo() {
var xhr
if (XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
xhr = ActiveXObject("XMLHttpRequest");
}
//ie5 和ie6是activeobject;
//请求方式,地址,是否异步;
//xhr.open("get", "../Handler/test.ashx", true);
xhr.open("post", "../Handler/test.ashx", true);
//发送请求
//设置请求的头部;
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//xhr.send();
xhr.send("a=3&b=4");
xhr.onreadystatechange = function (data) {
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
};
}