admin管理员组文章数量:1026989
What is the difference between these 3 calling methods? I'm using fetch in my current project and don't see any real difference between them. Why does there need to be 30 different ways to do things in javascript XD.
Thanks.
What is the difference between these 3 calling methods? I'm using fetch in my current project and don't see any real difference between them. Why does there need to be 30 different ways to do things in javascript XD.
Thanks.
Share Improve this question edited Mar 17, 2022 at 8:38 VLAZ 28.9k9 gold badges62 silver badges82 bronze badges asked Sep 10, 2018 at 15:30 Ext-Ext- 5313 gold badges8 silver badges16 bronze badges 2- 2 Possible duplicate of What is the difference between fetch and jquery ajax? – Frederik Spang Commented Sep 10, 2018 at 15:32
- 1 ajax is just a term, unless you mean jQuery's ajax method which just uses xhr internally – Patrick Evans Commented Sep 10, 2018 at 15:35
1 Answer
Reset to default 65Ajax is a buzzword meaning "Making an HTTP request from JavaScript without leaving the page".
XMLHttpRequest
and fetch
are APIs, provided by browsers, which allow HTTP requests to be made from JavaScript.
XMLHttpRequest
has been around since the 90s and is event-driven, requiring that you bind event listeners to detect when data has arrived.
fetch
is newer and built around Promises, which are now the prefered way to do asynchronous operations in JavaScript. It is sufficiently well established to be supported everywhere significant except in Internet Explorer. It does, however, lack certain features (such as progress monitoring) that XMLHttpRequest
provides.
So in short, there are two (not 30) purpose-built ways to do Ajax, and one of them is modern.
For practical introductions on how to use either of them, MDN has you covered:
- Using XMLHttpRequest
- Using Fetch
There are also various libraries which wrap around fetch
or XMLHttpRequest
to provide APIs which are situationally more convenient (e.g. a consistent API between Node.js and browsers or integration with a framework like Angular).
What is the difference between these 3 calling methods? I'm using fetch in my current project and don't see any real difference between them. Why does there need to be 30 different ways to do things in javascript XD.
Thanks.
What is the difference between these 3 calling methods? I'm using fetch in my current project and don't see any real difference between them. Why does there need to be 30 different ways to do things in javascript XD.
Thanks.
Share Improve this question edited Mar 17, 2022 at 8:38 VLAZ 28.9k9 gold badges62 silver badges82 bronze badges asked Sep 10, 2018 at 15:30 Ext-Ext- 5313 gold badges8 silver badges16 bronze badges 2- 2 Possible duplicate of What is the difference between fetch and jquery ajax? – Frederik Spang Commented Sep 10, 2018 at 15:32
- 1 ajax is just a term, unless you mean jQuery's ajax method which just uses xhr internally – Patrick Evans Commented Sep 10, 2018 at 15:35
1 Answer
Reset to default 65Ajax is a buzzword meaning "Making an HTTP request from JavaScript without leaving the page".
XMLHttpRequest
and fetch
are APIs, provided by browsers, which allow HTTP requests to be made from JavaScript.
XMLHttpRequest
has been around since the 90s and is event-driven, requiring that you bind event listeners to detect when data has arrived.
fetch
is newer and built around Promises, which are now the prefered way to do asynchronous operations in JavaScript. It is sufficiently well established to be supported everywhere significant except in Internet Explorer. It does, however, lack certain features (such as progress monitoring) that XMLHttpRequest
provides.
So in short, there are two (not 30) purpose-built ways to do Ajax, and one of them is modern.
For practical introductions on how to use either of them, MDN has you covered:
- Using XMLHttpRequest
- Using Fetch
There are also various libraries which wrap around fetch
or XMLHttpRequest
to provide APIs which are situationally more convenient (e.g. a consistent API between Node.js and browsers or integration with a framework like Angular).
本文标签: javascriptDifference between fetchAjaxand xhrStack Overflow
版权声明:本文标题:javascript - Difference between fetch, ajax, and xhr - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1737440275a1473443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论