我的第一个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">
 
相关文档:
最近网上提的很多的一个新概念就是 AJAX 了, 那么, AJAX 是什么呢? 以下内容引用网上资料:
AJAX全称为“Asynchronous JavaScript and XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。它有机地包含了以下几种技术:
Ajax(Asynchronous JavaScript + XML)的定义
基于 web标准(sta ......
Client端
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script language="javascript">
var XmlHttp=new ActiveXObject("Microsoft.XMLhttp");
function sendAJAX()
{
&nb ......
Ajax表单提交数据出现乱码和解决办法
//要传递的参数
var queryString = "firstName=" + firstName + "&lastName=" + lastName
&nbs ......
ajax请求不返回html代码的三种方式
ajax请求代码:
function ajaxSend() {
$.ajax({
url: “Test_Ajax.aspx”,
type: “post”,
data: { name: “ajax” },//如果请求的自身页面,为了在后台判断是不是ajax请求
error: function(xhr, textStatus, errorThown) {
alert(errorThown) ......