【问题标题】:Error: Cross origin localhost forbidden on Ajax call ScalaJS错误:Ajax 调用 ScalaJS 上禁止跨源本地主机
【发布时间】:2021-06-03 16:35:22
【问题描述】:

我正在尝试在维基百科上执行一个简单的“GET”:

Ajax.get("https://en.wikipedia.org/w/index.php?title=Special:Random") map (_.responseText)

我在尝试运行时收到此错误:

[error] org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error]         at org.scalajs.jsenv.ExternalJSRun$$anon$1.run(ExternalJSRun.scala:186)
[error] stack trace is suppressed; run 'last Compile / run' for the full output
[error] (Compile / run) org.scalajs.jsenv.ExternalJSRun$NonZeroExitException: exited with code 1
[error] Total time: 3 s, completed Mar 4, 2021, 4:47:42 PM
Error: Cross origin http://localhost forbidden
    at dispatchError (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:62:19)
    at Object.validCORSHeaders (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:74:5)
    at Request.<anonymous> (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\jsdom\lib\jsdom\living\xhr\XMLHttpRequest-impl.js:673:25)
    at Request.emit (events.js:315:20)
    at Redirect.onResponse (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\request\lib\redirect.js:147:11)
    at Request.onRequestResponse (C:\Users\mjwin\IdeaProjects\wiki-brain\node_modules\request\request.js:986:22)
    at ClientRequest.emit (events.js:315:20)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
    at TLSSocket.socketOnData (_http_client.js:509:22) {
  type: 'XMLHttpRequest'
}

我已经四处寻找有关此错误的信息,但我仍然不确定它的含义。我想我知道我遇到了 CORS 问题,但我不知道该怎么做。

【问题讨论】:

    标签: ajax xmlhttprequest cross-domain scala.js


    【解决方案1】:

    您需要允许将文件读入 URL:

    跨域读取阻塞 (CORB) 阻止了跨域响应

    不允许您的网址访问。您的脚本出错了。

    【讨论】:

    • 只有 wikipedia.org 选择谁被允许
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 2011-04-20
    • 1970-01-01
    • 2021-01-20
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多