我的第一个ajax 自动完成
一周前,leader让我写一个类似百度的自动完成功能,呵呵,因为对ajax技术掌握的不好,所以苦恼了很久没有写出来
经过一周的学习,终于写出了一个ajax程序,以后的工作就好做多啦
index.jsp
<html>
<head>
<style >
#child{
color: #333;
width:200px;
height:200px;
border: 1px black;
}
ul,li{
margin-left:25px;
list-style: none;
line-height: 20px;
}
</style>
<script type="text/javascript">
var xmlHttp;
function autoSelect(word){
var keywd = word.value;
var url ="test.do?keywd="+escape(keywd);
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
xmlHttp.open("post",url);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);s
}
function callback(){
if(xmlHttp.readyState ==4){
if(xmlHttp.status ==200){
var temp = xmlHttp.responseText;
var temparray = new Array();
if(temp != ''){
temparray = temp.split("?");
var str="<ul>";
for(i=1;i<temparray.length;i++){
str +="<li>"+temparray[i]+"</li>";
}
str +="</ul>";
document.getElementById("child").innerHTML =unescape(str);
}
}
}
}
</script>
</head>
<body>
<form action="test.do" method="post">
相关文档:
有很久一段时间我的BLOG上没有出现AJAX相关讯息了,主要当然是因为绝大部分的重心都放到了Silverlight身上(可预期的未来应该也会是如此)。
但由于工作上的需要,最近还是回头看了一下即将推出的ASP.NET Ajax Library...,顺便找了一下网络上的讯息,看这个态势我猜想应该不少ASP.NET开发人员忽略掉了这个其实已经bet ......
用struts2+jquery+json+hibernate+ajax做了一个登陆的demo。
1.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/x ......
代码下载:http://code.google.com/p/ajaxautocomplete/downloads/list
Auto Complete的jQuery控件。
首先是需要设计下我们的DIV最后应该显示成什么样子,我的CSS不咋地。瞎玩呢。样子如下:
首先是一个DIV,然后是添加一个ul和几个li tag:
<div id="nav">
<ul>
<li><a>Text1 field1& ......
oad()方法
load( url [,data] [,callback]) data是Object类型,发送至服务器的key/value数据
例:
$(function(){
$("#send").click(function(){
$("#resText").load("test.html ......