【问题标题】:Including react's jsx file in script tag gives error [duplicate]在脚本标签中包含反应的 jsx 文件会产生错误 [重复]
【发布时间】:2015-06-21 00:21:14
【问题描述】:

我有一些 react js 代码,如果我将它嵌入到我的 index.html 中就可以了。但是,当我尝试从外部 .jsx 文件中引用该代码时,它无法访问该代码并引发错误。请帮忙。

这就是我引用 jsx 文件的方式

<script type="text/jsx" src="autocomplete_js/custom_react.jsx">

这些是我得到的错误:

资源解释为脚本,但使用 MIME 类型 text/plain 传输:“file:///C:/react/autocomplete_js/custom_react.jsx”

XMLHttpRequest 无法加载 file:///C:/react/autocomplete_js/custom_react.jsx。跨域请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    确保您的文件由网络服务器(Apache 或 Ngnix)提供服务。

    我都试过了,当文件由 Apache 提供时,它就像一个魅力,当直接在 Chrome 中打开时(Safari 没有问题),我有同样的错误。

    【讨论】:

    • 在 python 烧瓶上测试过。工作过
    猜你喜欢
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 2021-02-26
    • 2016-05-18
    • 1970-01-01
    • 2018-01-25
    • 2016-12-17
    • 1970-01-01
    相关资源
    最近更新 更多