• <bdo id='xCjUr'></bdo><ul id='xCjUr'></ul>
        <tfoot id='xCjUr'></tfoot>

        <small id='xCjUr'></small><noframes id='xCjUr'>

        <legend id='xCjUr'><style id='xCjUr'><dir id='xCjUr'><q id='xCjUr'></q></dir></style></legend>
        <i id='xCjUr'><tr id='xCjUr'><dt id='xCjUr'><q id='xCjUr'><span id='xCjUr'><b id='xCjUr'><form id='xCjUr'><ins id='xCjUr'></ins><ul id='xCjUr'></ul><sub id='xCjUr'></sub></form><legend id='xCjUr'></legend><bdo id='xCjUr'><pre id='xCjUr'><center id='xCjUr'></center></pre></bdo></b><th id='xCjUr'></th></span></q></dt></tr></i><div id='xCjUr'><tfoot id='xCjUr'></tfoot><dl id='xCjUr'><fieldset id='xCjUr'></fieldset></dl></div>

        XMLHttpRequest 模块未定义/未找到

        时间:2023-05-16
        <i id='sWnGy'><tr id='sWnGy'><dt id='sWnGy'><q id='sWnGy'><span id='sWnGy'><b id='sWnGy'><form id='sWnGy'><ins id='sWnGy'></ins><ul id='sWnGy'></ul><sub id='sWnGy'></sub></form><legend id='sWnGy'></legend><bdo id='sWnGy'><pre id='sWnGy'><center id='sWnGy'></center></pre></bdo></b><th id='sWnGy'></th></span></q></dt></tr></i><div id='sWnGy'><tfoot id='sWnGy'></tfoot><dl id='sWnGy'><fieldset id='sWnGy'></fieldset></dl></div>
        • <small id='sWnGy'></small><noframes id='sWnGy'>

            <tfoot id='sWnGy'></tfoot>

                  <tbody id='sWnGy'></tbody>
                <legend id='sWnGy'><style id='sWnGy'><dir id='sWnGy'><q id='sWnGy'></q></dir></style></legend>
                • <bdo id='sWnGy'></bdo><ul id='sWnGy'></ul>

                  本文介绍了XMLHttpRequest 模块未定义/未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这是我的代码:

                  var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
                  var xhr = new XMLHttpRequest();
                  xhr.open("GET", "//URL")
                  xhr.setRequestHeader("Content-Type: application/json", "Authorization: Basic //AuthKey");
                  xhr.send();
                  

                  我收到错误:

                  Cannot find module 'xmlhttprequest'
                  

                  当我删除第一行时,我得到:

                  When I remove the first line, I am getting:

                  XMLHttpRequest is not defined
                  

                  我到处搜索,人们到处都提到了 Node.js 的问题,但我的 Node 安装是正确的,所以我不确定问题是什么.

                  I have searched all over and people have mentioned a problem with Node.js here and there but my installation of Node was correct so I'm not sure what the issue is.

                  推荐答案

                  XMLHttpRequest 是网络浏览器中的内置对象.

                  XMLHttpRequest is a built-in object in web browsers.

                  它不与 Node.js 一起分发.http 模块 是从 Node 发出 HTTP 请求的内置工具.

                  It is not distributed with Node. The http module is the built-in tool for making HTTP requests from Node.

                  大多数从节点发出 HTTP 请求的人都使用具有更友好 API 的第三方库.两个流行的选择是 Axios(用于 Node.js 和浏览器)和 node-fetch (它实现了浏览器内置的 fetch API,是XMLhttpRequest 的现代替代品.

                  Most people making HTTP requests from node use a third party library with a friendlier API. Two popular choices are Axios (for use both in Node.js and browsers) and node-fetch (which implements the fetch API which is built into browsers and is a modern replacement for XMLhttpRequest.

                  如果你真的想在 Node.js 中使用 XHR,那么有几个第三方实现.xmlhttprequest (似乎没有维护)和 xhr2(今年有更新).

                  If you really want to use XHR in Node.js then there are a couple of third party implementations. xmlhttprequest (which seems to be unmaintained) and xhr2 (which has had an update this year).

                  1. 用 npm 安装,

                  1. Install it with npm,

                   npm install xhr2
                  

                • 现在你可以在你的代码中require它.

                   var XMLHttpRequest = require('xhr2');
                   var xhr = new XMLHttpRequest();
                  

                • 这篇关于XMLHttpRequest 模块未定义/未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:显示使用 XHR2/AJAX 下载文件的进度条 下一篇:SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝

                  相关文章

                      <bdo id='Uew58'></bdo><ul id='Uew58'></ul>
                    <tfoot id='Uew58'></tfoot>
                      <i id='Uew58'><tr id='Uew58'><dt id='Uew58'><q id='Uew58'><span id='Uew58'><b id='Uew58'><form id='Uew58'><ins id='Uew58'></ins><ul id='Uew58'></ul><sub id='Uew58'></sub></form><legend id='Uew58'></legend><bdo id='Uew58'><pre id='Uew58'><center id='Uew58'></center></pre></bdo></b><th id='Uew58'></th></span></q></dt></tr></i><div id='Uew58'><tfoot id='Uew58'></tfoot><dl id='Uew58'><fieldset id='Uew58'></fieldset></dl></div>
                      <legend id='Uew58'><style id='Uew58'><dir id='Uew58'><q id='Uew58'></q></dir></style></legend>
                    1. <small id='Uew58'></small><noframes id='Uew58'>