

排错:调用 rxjs 的 ajax 报 'CORS is not supported by your browser'
source link: https://blog.dteam.top/posts/2021-04/cors-is-not-supported-by-your-browser-in-rxjs.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

排错:调用 rxjs 的 ajax 报 'CORS is not supported by your browser'
调用 rxjs 中的 ajax 方法,结果返回以下错误信息:
throw new Error('CORS is not supported by your browser');
^
Error: CORS is not supported by your browser
at getCORSRequest (./node_modules/rxjs/internal/observable/dom/AjaxObservable.js:28:1)
at Object.createXHR (./node_modules/rxjs/internal/observable/dom/AjaxObservable.js:94:1)
at AjaxSubscriber.module.exports.__webpack_modules__.2939.AjaxSubscriber.send (./node_modules/rxjs/internal/observable/dom/AjaxObservable.js:167:1)
at new AjaxSubscriber (./node_modules/rxjs/internal/observable/dom/AjaxObservable.js:149:1)
at AjaxObservable.module.exports.__webpack_modules__.2939.AjaxObservable._subscribe (./node_modules/rxjs/internal/observable/dom/AjaxObservable.js:117:1)
at AjaxObservable.Observable._trySubscribe (./node_modules/rxjs/internal/Observable.js:44:1)
at AjaxObservable.Observable.subscribe (./node_modules/rxjs/internal/Observable.js:30:1)
at MapOperator.module.exports.__webpack_modules__.8230.MapOperator.call (./node_modules/rxjs/internal/operators/map.js:32:1)
at Observable.subscribe (./node_modules/rxjs/internal/Observable.js:25:1)
问题的根源可不像看上去的那样明了,并非你去查 api 手册加上跟 cors 相关的配置就可以解决的。这个错误跟这个 issue 有关,虽然其状态是 closed
但其实一直并未修复,起码在当前的 rxjs 6 上依旧有这样的问题。
解决之道在上述 issue 的评论中已经给出:
- 安装
xmlhttprequest
(对于TypeScript
则是xmlhttprequest-ts
) - 然后采用下面类似的代码:
function simpleAsync() {
ajax({
url: 'https://blog.dteam.top/posts.html',
// 记得 import {XMLHttpRequest} from 'xmlhttprequest-ts';
createXHR: () => new XMLHttpRequest(),
})
.pipe(
...
)
.subscribe(res => {
...
});
其余则按需自行查阅文档进行配置吧,😄
Recommend
-
138
In the video below, I demonstrate how you can go about to create a rich and complex web app, with server-side bindings, at least in theory from your iPhone's browser. For the record, coding on an iPhone is not comfortable (obviously), but with H...
-
30
问题描述:因人员递增及业务发展需要,需要对现阶段Exchange前后端及数据库进行全新规划,并根据实际需要扩容现有数据库。在挂载数据库时发生报错MapiExceptionTooManyMountedDatabases: Unable to mount database。环境描述:Windows Server 2012R2 + Exchange CU...
-
30
-
19
排错:调用只读方法时,遇到 UNPREDICTABLE_GAS_LIMIT胡键 Posted at — Mar 10, 2021 阅读 78开发以太坊应用时,调用只读方法时遇到类似以下内容的报错信息:ERROR Error: Uncaught (in promise): Error: c...
-
7
how to redirect the browser during an ajax call (created with jQuery) to php advertisements i am facing a problem of redirecting the site whil...
-
9
利用跨域资源共享(CORS)实现ajax跨域调用 浏览:3024次 出处信息 前几天看了一篇E文说部署CORS
-
23
V2EX › 问与答 ajax 上传 cors 错误 fangwen...
-
8
排错:调用 parseLog 报 data out-of-bounds 错误 胡键 Posted at — Mar 16, 2023 阅读 9 调用 parseLog 解析日志,结果得到: UnhandledPromiseRejectionWarning: Error: data out-of-bounds (length=...
-
10
JavaScript import maps are now supported cross-browserWith import maps, importing ES modules now becomes a lot better.Mar 28, 2023 CelebrationThis web featur...
-
9
解决ajax post提交 跨域 cors问题 2023年 8月 一 二 三 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK