<script language="javascript" type="text/javascript"><!--
var ajaxRequest = null;
function getAjaxRequestObject() {
try {
// Firefox, Opera 8.0+, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return ajaxRequest;
}
function ajaxRequest() {
if (!ajaxRequest) {
alert("ajax创建失败!");
return false;
}
ajaxRequest.onreadystatechange = handleResponse;
ajaxRequest.open("POST","JavaServlet.java",true);//第三个参数true为同步,false为异步
ajaxRequest.send(null);
}
function handleResponse() {
if (ajaxRequest.readyState == 4) { // handleResponse()方法会被调用4次,readyState的值从1到4,readyState == 4表示返回服务器响应
if (ajaxRequest.status == 200) { // 请求成功
alert("The server replied with:" + ajaxRequest.responseText); // responseText:服务器返回的String对象
}
}
}
--></script>
var ajaxRequest = null;
function getAjaxRequestObject() {
try {
// Firefox, Opera 8.0+, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return ajaxRequest;
}
function ajaxRequest() {
if (!ajaxRequest) {
alert("ajax创建失败!");
return false;
}
ajaxRequest.onreadystatechange = handleResponse;
ajaxRequest.open("POST","JavaServlet.java",true);//第三个参数true为同步,false为异步
ajaxRequest.send(null);
}
function handleResponse() {
if (ajaxRequest.readyState == 4) { // handleResponse()方法会被调用4次,readyState的值从1到4,readyState == 4表示返回服务器响应
if (ajaxRequest.status == 200) { // 请求成功
alert("The server replied with:" + ajaxRequest.responseText); // responseText:服务器返回的String对象
}
}
}
--></script>