Ajax (also AJAX; short for asynchronous Javascript and XML) is a group of interrelated Web develoment techniques used on the client-side to create asynchronous Web appications. With Ajax, web aplications can send data to and retrieve from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used in teh AJAJ variant), and the requests do not need to be asynchronous.

Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display - and allow the user to interact with - the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

">
立诚勿怠,格物致知
It's all about connecting the dots

AJAX

Introduction

Here is the description of Ajax from Wikipedia:

Ajax (also AJAX; short for asynchronous Javascript and XML) is a group of interrelated Web develoment techniques used on the client-side to create asynchronous Web appications. With Ajax, web aplications can send data to and retrieve from a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used in teh AJAJ variant), and the requests do not need to be asynchronous.

Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display – and allow the user to interact with – the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.


Using XMLHttpRequest

To use XMLHttpRequest, you must understand the three ways of creating an XMLHttpRequest object:

  1. IE 5: request = new ActiveXOjbect(“MIcrosoft.XMLHPPT”)
  2. IE 6+: request = new ActiveXObject(“Msxml2.XMLHTTP”)
  3. All others: new XMLHttpRequest()

Therefore, the code below will work for all major browsers released over the last few years.


//A cross-browser Ajax function

Table: An XMLHttpRequest object’s properties
Properties Description
onreadystatechange Specified an event handing function to be called whenever the readyState property of an object changes.
readyState An integer property that reports on the status of a request. It can have any of these values:
0 = Uninitialized
1 = Loading
2 = Loaded
3 = Interactive
4 = Completed
responseText The data returned by the server in text format.
responseXML The data returned by the server in XML format.
status The HTTP status code returned by the server.
statusText The HTTP status text returned by the server.
Table: An XMLHttpRequest object’s methods
Methods Description
abort() Aborts the current request
getAllResponseHeaders() Returns all headers as a string
getResponseHeader(param) Returns the value of param as a string
open(‘method‘,’url‘,’asynch‘) Specifies the HTTP method to use (GET or POST), the target URL, and whether the request should be handled asynchronously (true or false)
send(data) Sends data to the tareget server using the specified HTTP method
setRequestHeader(‘param‘,’value‘) Sets a header with a parameter/value pair
赞(0) 打赏
文章名称:《AJAX》
文章链接:https://www.orzzone.com/ajax.html
商业联系:yakima.public@gmail.com

本站大部分文章为原创或编译而来,对于本站版权文章,未经许可不得用于商业目的,非商业性转载请以链接形式标注原文出处。
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力提供更多优质内容!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册