//javascript格式
function btnClick() {
var xmlHttp;
function createXMLHttpRequst() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
if (!xmlHttp) {
alert('创建xmlHttp异常');
}
xmlHttp.open("POST", "GetDate.ashx", false);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
document.getElementById("text1").value = xmlHttp.responseText;
}
else {
alert('ajax服务器返回错误');
}
}
};
xmlHttp.send();
}
//JQurery格式
$(function () {
$("#btnGet").click(function () {
var sum = $("#text1").val();
var type = $("#Select1").val();
var xmlHttp;
function createXMLHttpRequst() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
if (!xmlHttp) {
alert('创建xmlHttp对象异常');
}
xmlHttp.open("GET", "GetHuilv.ashx?num=" + sum + "&type=" + type, false);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.readystatus == 200) {
$("#text2").val(xmlHttp.responseText);
}
else {
alert('ajax服务器返回错误');
}
}
}; xmlHttp.send();
});
});