AJAX浏览器

http://www.w3pop.com/learn/view/p/1/o//doc/ajax_browsers/

AJAX applications can only run in web browsers with XML support.
AJAX应用程序只可以在支持XML的浏览器上运行


AJAX Browser Support
浏览器对AJAX的支持

AJAX applications can only run in web browsers with complete XML support.
AJAX只能运行在那些完全支持XML的浏览器上

Only two web browsers available today - Internet Explorer (IE) and Mozilla Firefox.- have complete enough support for XML to run AJAX applications.
目前只有两个浏览器是符合这个要求的 - IE和火狐 - 它们对XML的支持足以运行AJAX程序

Since other browsers like Safari and Opera have limited, incomplete or incorrect XML support, this tutorial will focus on IE and Firefox examples.
其它浏览器在此方面有局限性(比如Safari 和 Opera),所以它们对XML的支持还不完全,这个教程会主要针对IE和FF浏览器进行举例


The example on the previous page called a function called GetXmlHttpObject.
上一页的举例调用了名为GetXmlHttpObject的函数

The purpose of the function is to solve the problem of creating different XMPHTTP objects for different browsers.
使用这个函数的目的是为了解决针对不同浏览器建立不同的XMPHTTP对象而设计的。

The function is listed below:
函数是这样的:

function GetXmlHttpObject(handler)
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

 


完整的代码

The full source code to the example is listed in the next chapter.
举例的完整代码在下一篇中。

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

<html>
<head>
<script src="clienthint.js"></script>
</head>
<body>
<form> 
First Name:

<input type="text" id="txt1"
οnkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p> 
</body>
</html>

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服务器端页面的解释放在下一篇中。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值