fetch,ajax和xhr之间的区别 [英] Difference between fetch, ajax, and xhr

查看:39
本文介绍了fetch,ajax和xhr之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这三种调用方法之间有什么区别?我在当前项目中使用抓取功能,但看不到它们之间的任何实际区别.为什么需要使用30种不同的方式在javascript XD中进行操作.

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.

谢谢.

推荐答案

Ajax是一个时髦的词,意思是从JavaScript发出HTTP请求而无需离开页面".

Ajax is a buzzword meaning "Making an HTTP request from JavaScript without leaving the page".

XMLHttpRequest fetch 是浏览器提供的API,它们允许通过JavaScript发出HTTP请求.

XMLHttpRequest and fetch are APIs, provided by browsers, which allow HTTP requests to be made from JavaScript.

XMLHttpRequest 自90年代就存在并且是事件驱动的,要求您绑定事件侦听器以检测数据何时到达.

XMLHttpRequest has been around since the 90s and is event-driven, requiring that you bind event listeners to detect when data has arrived.

fetch 是较新的并且围绕Promises构建,Promises现在是在JavaScript中执行异步操作的首选方法.除了Internet Explorer以外,其他任何重要地方都可以得到支持.

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.

简而言之,有两种(不是30种)专门构建Ajax的方法,其中一种是现代的.

So in short, there are two (not 30) purpose-built ways to do Ajax, and one of them is modern.

有关如何使用这两种方法的实用介绍,MDN已为您介绍:

For practical introductions on how to use either of them, MDN has you covered:

这篇关于fetch,ajax和xhr之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆