我的第一个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">
 
相关文档:
一.工具下载
1.ASPAJAXExtSetup.msi
http://download.microsoft.com/download/5/4/6/5462bcbd-e738-45fa-84ca-fa02b0c4e1c2/ASPAJAXExtSetup.msi
2.ASPAJAXSourceCode.msi
http://download.microsoft.com/download/6/d/6/6d6c7c47-b9ff-4934-bb03-8a45b8418d35/ASPAJAXSourceCode.msi
3.AjaxControlToolkit
http://ww ......
注意:$.get()和$.post()方法是jQuery中的全局函数。前面讲到的load()方式是对jQuery对象进行操作的。
1、 $.get()方法
$.get()方法使用GET方式来进行异步请求。
它的语法结构为:
$.get( url [, data] [, callback] [, type] )
$.get()方法参数解释如下表:
参数名称
类 型
说 明
url
Strin ......
到最后我才发现微软给的ajax json 实例都是有问题的,很多都是不严密的,特别是对于大小写方面,他们都没有仔细追究大小写问题,导致了在firefox使用有问题。下面是实例内用:两个html之间的:
<head> <title>测试ajax</title> <meta http-equiv=”Content-Type” content=”text/ht ......
<!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="Content-Type" content="text/html; charset=gb2312" />
<title>简单的应用XMLHt ......