jsp+ajax×Ô¶¯Ë¢ÐÂʵÀý(ת)
Ò»¡¢´¦ÀíajaxÇëÇóµÄjspÎļþ£ºauto.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%
//ÉèÖÃÊä³öÐÅÏ¢µÄ¸ñʽ¼°×Ö·û¼¯
response.setContentType("text/xml; charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
out.println("<response>");
for(int i=0;i<2;i++){
out.println("<name>"+(int)(Math.random()*10)+
"ÐͱʼDZ¾</name>");
out.println("<count>" +(int)(Math.random()*100)+ "</count>");
}
out.println("</response>");
out.close();
%>
¶þ¡¢·¢ËÍajaxÇëÇóµÄhtmlÎļþ£ºautoRefresh.html
<head>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
</head>
<script language="javascript">
var XMLHttpReq;
//´´½¨XMLHttpRequest¶ÔÏó
function createXMLHttpRequest() {
if(window.XMLHttpRequest) { //Mozilla ä¯ÀÀÆ÷
XMLHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) { // IEä¯ÀÀÆ÷
try {
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
}
//·¢ËÍÇëÇóº¯Êý
function sendRequest() {
createXMLHttpRequest();
var url = "auto.jsp";
XMLHttpReq.open("GET", url, true);
XMLHttpReq.onreadystatechange = processResponse;//Ö¸¶¨ÏìÓ¦º¯Êý
XMLHttpReq.send(null); // ·¢ËÍÇëÇó
}
// ´¦Àí·µ»ØÐÅÏ¢º¯Êý
function processResponse() {
if (XMLHttpReq.readyState == 4) { // Åж϶ÔÏó״̬
if (XMLHttpReq.status == 200) { // ÐÅÏ¢ÒѾ³É¹¦·µ»Ø£¬¿ªÊ¼´¦ÀíÐÅÏ¢
DisplayHot();
setTimeout("sendRequest()", 1000);
} else { //Ò³Ãæ²»Õý³£
window.alert("ÄúËùÇëÇóµÄÒ³ÃæÓÐÒì³£¡£");
Ïà¹ØÎĵµ£º
<html>
<head>
<title>marquee</title>
<style>
#marq {
width:500px;
height:100px;
border:1px solid red;
overflow:hidden;
}
#mar ......
404´íÎóÊÇʲôʱºò²úÉúµÄÄØ£¿µ±ÎÒÃÇͨ¹ýä¯ÀÀÆ÷ÇëÇó·þÎñÆ÷ÉϵÄij¸ö×ÊÔ´µÄʱºò£¬¿ÉÄÜÊÇJSP£¬Ò²¿ÉÄÜÊÇServlet£¬Èç¹ûÒª·ÃÎʵÄ×ÊÔ´²»´æÔÚ£¬¾Í»á²úÉú404´íÎó£¬404´íÎó¿ÉÄÜÊÇÓ¦Óñ¾ÉíµÄÎÊÌ⣬ÀýÈçûÓÐÕý³£²¿Êð¡¢Ãû×Öд´íÁË£¬Ò²¿ÉÄÜÊÇÎļþµÄÎÊÌ⣬JSPÎļþ²»´æÔÚ¡¢Ãû×Ö´íÎ󣬻òÕßServleûÓÐÅäÖá£
¸ù¾ÝÕâЩÇé¿ö£¬404´íÎóµÄ½â¾ ......
ÀûÓÃAJAX¶¯Ì¬»ñÈ¡µ±Ç°Ê±¼ä£¬¿Í»§¶Ëtime.php,·þÎñÆ÷¶Ëtime_check.php
¿Í»§¶Ë´úÂ룺
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=" ......
×î½ü×öÍøÕ¾Óõ½ÁËUpProgress¿Ø¼þ£¬ËùÒÔ°ÑÓöµ½µÄÎÊÌâºÍ×Ô¼ºµÄ¿´·¨Ð´ÏÂÀ´£¬¹©ÒÔºó²Î¿¼£¬Ò²Ï£Íû¸ø´ó¼Ò´úÂë°ïÖú¡£
UpProgressÊǺÍUpdatePanelÒ»ÆðʹÓõġ£ÊµÏÖЧ¹û¾ÍÊÇÔÚÌá½»µ½·þÎñÆ÷µÄʱºò£¬ÏÔʾÌáʾ£¬±ÈÈ磺“Êý¾Ý¼ÓÔØÖУ¬ÇëÉÔ΢..”¸ø ......