有Ajax怎样完成无刷新的页面谢谢了 有Ajax怎样完成无刷新的页面谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ajax入门 找一个例子做一遍就好了innerHTML最简单XML复杂一点 用jQuery来实现比较容易,下个jQuery API文档看看就明白了. 给你个例子前台.JSP<%@ page language="java" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'ajaxIndex.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> function test(){ var url = "getData.jsp?username="+document.getElementById("username").value; sendRequest(url); } var XMLHttpReq = false; //创建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(url) { createXMLHttpRequest(); XMLHttpReq.open("GET", url, true); XMLHttpReq.onreadystatechange = processResponse;//指定响应函数 XMLHttpReq.send(null); // 发送请求 } // 处理返回信息函数 function processResponse() { if (XMLHttpReq.readyState == 4) { // 判断对象状态 if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息 var result = XMLHttpReq.responseText; document.getElementById("data").innerHTML = result; } else { //页面不正常 window.alert("您所请求的页面有异常。"); } } } </script> </head> <body> <table> <tr> <td>ajax提取数据:</td> </tr> <tr><td><div id="data">原始数据</div></td></tr> <tr><td><input type="text" name="username" id="username"/></td></tr> <tr><td><input type="button" value="submit" onclick="test()"/></td></tr> </table> </body> </html>后台.JSP<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% out.print("username is :"+request.getParameter("username")); %> $.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg ); }}); 国际象棋棋盘输出问题 急:APPLET嵌入HTML问题 怎么用BufferedIamge创建一个黑白图片 小程序,不知道那里错了。。。 我想学习java 如何在一个网站里既有asp页面,也有jsp页面 java在后台生成excel时如何将生成的文件放到自己指定的目录下面? O'REILLY关于JAVA四个包的书名字是什么 关于重画的问题 没想到配JAVA环境这么难! 基础问题 applet中panel被其他panel覆盖的问题
XML复杂一点
前台.JSP
<%@ page language="java" pageEncoding="UTF-8"%>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head> <base href="<%=basePath%>">
<title>My JSP 'ajaxIndex.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> function test(){ var url = "getData.jsp?username="+document.getElementById("username").value; sendRequest(url); } var XMLHttpReq = false; //创建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(url) { createXMLHttpRequest(); XMLHttpReq.open("GET", url, true); XMLHttpReq.onreadystatechange = processResponse;//指定响应函数 XMLHttpReq.send(null); // 发送请求 } // 处理返回信息函数 function processResponse() { if (XMLHttpReq.readyState == 4) { // 判断对象状态 if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息 var result = XMLHttpReq.responseText; document.getElementById("data").innerHTML = result; } else { //页面不正常 window.alert("您所请求的页面有异常。"); } } } </script> </head> <body> <table> <tr> <td>ajax提取数据:</td> </tr> <tr><td><div id="data">原始数据</div></td></tr> <tr><td><input type="text" name="username" id="username"/></td></tr> <tr><td><input type="button" value="submit" onclick="test()"/></td></tr> </table> </body> </html>后台.JSP
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% out.print("username is :"+request.getParameter("username")); %>
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});