新接触的项目中使用的Fetch技术发送网络请求,本来想对比一下传统的XHR与fetch 的区别。但是翻阅他人博客时,发现AJAX和XHR的关系不明,有博客认为XHR和fetch都是实现AJAX请求的方法,也有博客直接认为XHR就是AJAX。本人比较偏向第一种说法,因为AJAX并不是一个可以独立工作的技术,他更像是一种技术方案。一种为了解决在不刷新或重定向页面的前提下,实现与服务端的数据交互和客户端页面局部更新的技术方案。 而 XHR和Fetch都是这种技术方案中可以用来实现与服务端数据交互的技术。以下是翻译的https://www.tutorialspoint.com/ajax/what_is_ajax.htm。
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS, and Java Script.
AJAX 是Asynchronous JavaScript and XML的缩写。AJAX 是一项基于XML,HTML,CSS和Javascript 来创建更好,更快,更多交互的web 应用的新技术。(个人认为是技术方案,以下都以技术方案称之)
-
Ajax uses XHTML for content, CSS for presentation, along with Document Object Model and JavaScript for dynamic content display.
-
AJAX 技术方案使用 XHTML 来描述内容,CSS设置样式,DOM 和JS实现内容的动态展示。
-
Conventional web applications transmit information to and from the sever using synchronous requests. It means you fill out a form, hit submit, and get directed to a new page with new information from the server.
-
传统的Web 应用使用异步请求在客户端和服务器间传输数据。当填完一个表单后,点击提交,服务器会将前端重定向到一个有新数据的页面。
-
With AJAX, when you hit submit, JavaScript will make a request to the server, interpret the results, and update the current screen. In the purest sense, the user would never know that anything was even transmitted to the server.
-
但是当使用AJAX技术方案时,提交表单后,JS会发送一个请求到服务端,然后解析请求响应,并更新当前页面。从用户直观感受上,是感觉不到有数据被发送到了服务端的。
-
XML is commonly used as the format for receiving server data, although any format, including plain text, can be used.
-
XML 一般作为从服务端接收数据的格式,也可以使用其他格式,例如plain text。
-
AJAX is a web browser technology independent of web server software.
-
AJAX 是一项与web 服务软件(没搞清楚是什么)相独立的web浏览器技术。
-
A user can continue to use the application while the client program requests information from the server in the background.
- 当客户端在后台向服务端请求数据时,用户仍然可以继续使用应用。
-
Intuitive and natural user interaction. Clicking is not required, mouse movement is a sufficient event trigger.
-
AJAX技术方案提供更直观本能的用户交互体验。点击不再是必需的事件,鼠标的移动事件已足够。
-
Data-driven as opposed to page-driven.
-
相对于页面驱动, AJAX技术方案使用数据驱动;
Rich Internet Application Technology
富网络应用技术
AJAX is the most viable Rich Internet Application (RIA) technology so far. It is getting tremendous industry momentum and several tool kit and frameworks are emerging. But at the same time, AJAX has browser incompatibility and it is supported by JavaScript, which is hard to maintain and debug.
AJAX是目前RIA技术中可用性最高的一项技术方案。他在行业内势头极大,多个工具包和框架正在使用他。但是,AJAX也有浏览器兼容问题,他需要JS支持,难于维护和debug。
AJAX is Based on Open Standards
AJAX 是基于公开的标准。
AJAX is based on the following open standards −
AJAX 是基于以下公开的标准
- Browser-based presentation using HTML and Cascading Style Sheets (CSS).
- 浏览器上的展示使用HTML和CSS
- Data is stored in XML format and fetched from the server.
- 从服务端获取的数据以XML格式存储
- Behind-the-scenes data fetches using XMLHttpRequest objects in the browser
- 使用XHR在后台请求数据
- JavaScript to make everything happen.
- JS 负责实现整个环节