var $ = function(id) {
return document.getElementById(id);
}
//创建一个XMLHttpRequest对象
var createXHR = function() {
var xhr = false;
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xhr = false;
}
}
if (!xhr && typeof XMLHttpRequest != "undefined") {
xhr= new XMLHttpRequest();
}
//js处理服务器的响应
var updatePage = function(xhr) {
if (xhr.readyState == 4) {
var response = xhr.responseText;
alert(response);
}
}
//使用创建的XMLHttpRequest实例与服务器进行连接
function callServer() {
var param = $("param").value;
//Only go if there are values for both fields
if ((city == null))
return;
if ((state == null))
return;
//Build the URL to connect to
var url = "/script/getZipCode.jsp?param=" + escape(param);
//Open a connection to the server
var xhr = createXHR();
xhr.open("GET", url, true);
xhr.onreadystatechange = updatePage;
}
return document.getElementById(id);
}
//创建一个XMLHttpRequest对象
var createXHR = function() {
var xhr = false;
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xhr = false;
}
}
if (!xhr && typeof XMLHttpRequest != "undefined") {
xhr= new XMLHttpRequest();
}
if(!xhr){
alert("您的浏览器不支持ajax");
}
}
//js处理服务器的响应
var updatePage = function(xhr) {
if (xhr.readyState == 4) {
var response = xhr.responseText;
alert(response);
}
}
//使用创建的XMLHttpRequest实例与服务器进行连接
function callServer() {
var param = $("param").value;
//Only go if there are values for both fields
if ((city == null))
return;
if ((state == null))
return;
//Build the URL to connect to
var url = "/script/getZipCode.jsp?param=" + escape(param);
//Open a connection to the server
var xhr = createXHR();
xhr.open("GET", url, true);
xhr.onreadystatechange = updatePage;
}