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
本站内容仅供个人学习交流,不做为任何投资、建议的参考依据,因此产生的问题需自行承担。

评论 抢沙发

大前端WordPress主题 更专业 更方便

支持快讯、专题、百度收录推送、人机验证、多级分类筛选器,适用于垂直站点、科技博客、个人站,扁平化设计、简洁白色、超多功能配置、会员中心、直达链接、文章图片弹窗、自动缩略图等...

去看看

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

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

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册