Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Watch
Unwatch
Watching
Releases Only
Ignoring
3
Star
48
Fork
24
DreamCoders
/
CoderGuide
Code
Issues
1169
Pull Requests
0
Wiki
Insights
Pipelines
Service
JavaDoc
PHPDoc
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
说说 ajax 原理?
Backlog
#IAG9OP
陌生人
owner
Opened this issue
2024-07-29 16:06
<p>Ajax 的原理简单来说是在用户和服务器之间加了—个中间层( AJAX 引擎),由 XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用 javascrip t 来操作 DOM 而更新页面。使用户操作与服务器响应异步化。这其中最关键的一步就是从服务器获得请求数据。</p><p>Ajax 的过程只涉及 JavaScript 、 XMLHttpRequest 和 DOM 。 XMLHttpRequest 是 ajax 的核心机制。</p><h4>Ajax 的优点:</h4><p>通过异步模式,提升了用户体验</p><p>优化了浏览器和服务器之间的传输,减少不必要的数据往返,减少了带宽占用</p><p>Ajax 在客户端运行,承担了一部分本来由服务器承担的工作,减少了大用户量下的服务器负载</p><p>Ajax 可以实现动态不刷新(局部刷新)</p><h4>Ajax 的缺点:</h4><p>安全问题 AJAX 暴露了与服务器交互的细节</p><p>对搜索引擎的支持比较弱</p><p>不容易调试</p><h4>Ajax 的请求:</h4><pre><code class="language-javascript">/** 创建连接 **/ var xhr = null; xhr = new XMLHttpRequest() /** 2. 连接服务器 **/ xhr.open('get', url, true) /** 3. 发送请求 **/ xhr.send(null); /** 4. 接受请求 **/ xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { success(xhr.responseText); } else { /** false **/ fail && fail(xhr.status); } } }</code></pre><p><br></p>
<p>Ajax 的原理简单来说是在用户和服务器之间加了—个中间层( AJAX 引擎),由 XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用 javascrip t 来操作 DOM 而更新页面。使用户操作与服务器响应异步化。这其中最关键的一步就是从服务器获得请求数据。</p><p>Ajax 的过程只涉及 JavaScript 、 XMLHttpRequest 和 DOM 。 XMLHttpRequest 是 ajax 的核心机制。</p><h4>Ajax 的优点:</h4><p>通过异步模式,提升了用户体验</p><p>优化了浏览器和服务器之间的传输,减少不必要的数据往返,减少了带宽占用</p><p>Ajax 在客户端运行,承担了一部分本来由服务器承担的工作,减少了大用户量下的服务器负载</p><p>Ajax 可以实现动态不刷新(局部刷新)</p><h4>Ajax 的缺点:</h4><p>安全问题 AJAX 暴露了与服务器交互的细节</p><p>对搜索引擎的支持比较弱</p><p>不容易调试</p><h4>Ajax 的请求:</h4><pre><code class="language-javascript">/** 创建连接 **/ var xhr = null; xhr = new XMLHttpRequest() /** 2. 连接服务器 **/ xhr.open('get', url, true) /** 3. 发送请求 **/ xhr.send(null); /** 4. 接受请求 **/ xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { success(xhr.responseText); } else { /** false **/ fail && fail(xhr.status); } } }</code></pre><p><br></p>
Comments (
0
)
Sign in
to comment
Status
Backlog
Backlog
Doing
Done
Closed
Assignees
Not set
Labels
Html/JS/CSS
Not set
Label settings
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
参与者(1)
1
https://gitee.com/DreamCoders/CoderGuide.git
git@gitee.com:DreamCoders/CoderGuide.git
DreamCoders
CoderGuide
CoderGuide
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register