[求助] ajax的服务器端没有返回值?
服务器端 timeServer.jsp
<%@ page language= "java " contentType= "text/html;charset=utf-8 " %>
<% //服务器端
//禁止缓村
response.setHeader( "Pragma ", "No-cache ");
response.setHeader( "Cache-Control ", "no-cache ");
response.setDateHeader( "Expires ",0); //response.getWriter().write(beginTestTime.toString());
response.getWriter().write( "wxj ");
%>
客户端
<%@ page contentType= "text/html; charset=gb2312 " language= "java " %>
<html>
<head>
<script language= "javascript ">
function showTimeBefore(){
window.alert( "fdsdf ");
var xmlHttp;
if(window.ActiveXObject){
xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP ");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open( "GET ", "timeServer.jsp ",true);
xmlHttp.onreadystatechange=updateTime;
xmlHttp:send(null);
}
function updateTime()
{
if (xmlHttp.readyState == 4)
if (xmlHttp.readyState == 200)
{
var response=xmlHttp.responseText;
document.getElementById( "clock ").value= response;
alert( "Server is done! ");
}
else if (xmlHttp.readyState == 404)
alert( "Request URL does not exist ");
else
alert( "Error:status code is "+xmlHttp.status);
}
</script>
</head>
<body>
<form method= "get " name= "test "> <p> </p> <p> </p> <p>
<input type= "text " id= "clock " name= "clock "> </p> <p> </p> <p> </p> <p> </p>
<input type= "button " name= "button1 " onclick= "showTimeBefore() ">
</form>
</body>
</html>
[解决办法]
关注