日期:2015/6/28来源: IT猫扑网
Ajax很简单(jsp例子)
首先是jsp页面和脚本,为了方便写在一个里面
这是一个很常见的检测用户名是否存在的功能
这里用的是struts ,可以在路径path中加加上要传的值name 在action中连接数据库 验证是否存在
--------------------------------------------------------------------------------
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
ajax
</title>
</head>
<body bgcolor="#ffffff">
<h1>
<input name="username" type="text" maxlength="20" />
<input id="chk-name-btn" type="button" value="检测帐号" onclick="testName(’<%=request.getcontextPath()%>’)" />
<div id="view_name"></div>
</h1>
</body>
</html>
<script language="javascript">
if (window.ActiveXObject && !window.XMLHttpRequest) {
window.XMLHttpRequest=function() {
return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf(’msie 5’) != -1) ? ’Microsoft.XMLHTTP’ : ’Msxml2.XMLHTTP’);
};
}//取得XMLHttpRequest对象
function testName(path){
//path是取得系统路径
var view_name=document.getElementById("view_name");
var req=new XMLHttpRequest();
相关文章
相关下载
网友评论