Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

30.Ajax 的优缺点及工作原理? #30

Open
webVueBlog opened this issue Mar 13, 2020 · 1 comment
Open

30.Ajax 的优缺点及工作原理? #30

webVueBlog opened this issue Mar 13, 2020 · 1 comment
Labels
html html

Comments

@webVueBlog
Copy link
Member

定义和用法:

AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML)。
Ajax 是一种用于创建快速动态网页的技术。Ajax 是一种在无需重新加载整个网
页的情况下,能够更新部分网页的技术。

传统的网页(不使用 Ajax)如果需要更新内容,必须重载整个网页页面。

优点:

  1. 减轻服务器的负担,按需取数据,最大程度的减少冗余请求
  2. 局部刷新页面,减少用户心理和实际的等待时间,带来更好的用户体验
  3. 基于 xml 标准化,并被广泛支持,不需安装插件等,进一步促进页面和数据的分离

缺点:

  1. AJAX 大量的使用了 javascript 和 ajax 引擎,这些取决于浏览器的支持.在编写
    的时候考虑对浏览器的兼容性.
  2. AJAX 只是局部刷新,所以页面的后退按钮是没有用的.
  3. 对流媒体还有移动设备的支持不是太好等

AJAX 的工作原理:

  1. 创建 ajax 对象(XMLHttpRequest/ActiveXObject(Microsoft.XMLHttp))
  2. 判断数据传输方式(GET/POST)
  3. 打开链接 open()
  4. 发送 send()
  5. 当 ajax 对象完成第四步(onreadystatechange)数据接收完成,判断 http
    响应状态(status)200-300 之间或者 304(缓存)执行回调函数
@webVueBlog
Copy link
Member Author

Definition and usage:

AJAX = Asynchronous JavaScript and XML (Asynchronous JavaScript and XML).
Ajax is a technique for creating fast, dynamic web pages. Ajax is one way to do this without reloading the entire web
Page case, able to update part of the web page technology.

Traditional web pages (without Ajax) must reload the entire page if they need to be updated.

Advantages:

Reduce the burden on the server, fetch data on demand, and minimize redundant requests
Partial page refresh, reduce the user's psychological and actual waiting time, bring better user experience
Based on XML standardization, it is widely supported, no plug-ins need to be installed, etc., which further facilitates the separation of pages and data
Disadvantages:

AJAX makes extensive use of javascript and AJAX engines, depending on browser support
Consider browser compatibility.
AJAX is only a partial refresh, so the back button on the page is useless.
Streaming media and mobile device support is not too easy to wait
How AJAX works:

Create the ajax object (XMLHttpRequest/ActiveXObject (Microsoft. XMLHttp))
Determine the mode of data transfer (GET/POST)
Open link ()
Send the send ()
When the ajax object completes the fourth step (onreadystatechange) data reception, determine HTTP
The response status is between 200 and 300 or 304 (cache) executes the callback function

@webVueBlog webVueBlog added the html html label Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
html html
Projects
None yet
Development

No branches or pull requests

1 participant