【问题标题】:localhost - Cross origin requests are only supported for protocol schemes?localhost - 仅协议方案支持跨源请求?
【发布时间】:2018-06-29 23:35:05
【问题描述】:

我有以下功能:

this.Locations = axios.get('localhost:8081/fetchData?table=locations').then((res) => {                                         
  return res
})   

在我的 app.js 中,我设置了一个端点“/fetchData”,如果我只是在浏览器中执行,它就可以正常工作。

我怎么会收到这个错误信息?

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

【问题讨论】:

  • 指定http还是https?

标签: javascript axios


【解决方案1】:

您需要指定一个方案,例如http://。将您的功能更改为:

this.Locations = axios.get('http://localhost:8081/fetchData?table=locations').then((res) => {                                         
  return res
})   

【讨论】:

  • @NicollasBraga 因为绝对 URL 必须以方案名称开头。如果未定义,则无法确定使用哪种方案。这就是不允许该请求的原因。实际上,localhost:8081 甚至都不是有效的 URL。是的,如果我们在浏览器栏中输入它,浏览器会通过在它前面添加一个http://来修复它,但这样做只是为了用户方便
猜你喜欢
  • 1970-01-01
  • 2018-10-03
  • 2016-07-19
  • 1970-01-01
  • 2017-02-22
  • 2017-10-11
  • 2017-09-29
相关资源
最近更新 更多