繁体中文
设为首页
加入收藏
当前位置:网站制作首页 >> AJAX教程 >> AJAX代码

AJAX代码

2007-06-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:AJAX Example - AJAX Source AJAX 实例 - AJAX 源码 The source code below belongs to the AJAX example on the previous pages. 下面的源代码是前一个页面的。 You can copy and paste it, and try it yoursel...
关键字:代码 AJAX

AJAX Example - AJAX Source

AJAX 实例 - AJAX 源码

The source code below belongs to the AJAX example on the previous pages.

下面的源代码是前一个页面的。

You can copy and paste it, and try it yourself.

你可以将它复制并粘贴,自己来尝试。

The AJAX HTML Page

AJAX HTML页面

This is the HTML page. It contains a simple HTML form and a link to a JavaScript.

这是一个HTML网页。它包括了一个简单的HTML表单和关联JS的link

First Name:

Suggestions:

The JavaScript code is listed below.

JS代码在下面

The AJAX JavaScript

AJAX 的 JS

This is the JavaScript code, stored in the file "clienthint.js":

这是JS代码,被保存在"clienthint.js"文件中

var xmlHttp

function showHint(str)

{

if (str.length==0)

{

document.getElementById("txtHint").innerHTML=""

return

}

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}

var url="gethint.asp"

url=url+"?q="+str

url=url+"&sid="+Math.random()

xmlHttp.onreadystatechange=stateChanged

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("txtHint").innerHTML=xmlHttp.responseText

}

}

function GetXmlHttpObject()

{

var objXMLHttp=null

if (window.XMLHttpRequest)

{

objXMLHttp=new XMLHttpRequest()

}

else if (window.ActiveXObject)

{

objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

}

return objXMLHttp

}

The AJAX server page is explained in the next chapter.

有关AJAX服务器端页面的解释放在下一篇中。

责任编辑:admin
相关文章