您的位置:首页 > 理论基础 > 计算机网络

Ajax本地跨域问题 Cross origin requests are only supported for HTTP

2017-03-15 17:43 549 查看
在练习一个vue.js的项目时,通过vue-resource模块中的this.$http方法来获取一个本地的json串

var vm = new Vue({
el:'#shoppingCar',
data:{
title:'购物车'
},
filters:{

},
mounted:function(){
this.cartview();
},
methods:{
cartview:function(){
this.$http.get("data/cartData.json",{"id":123}).then(function(res){

});
}
}
})结果,报错如下:

Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource.
解决方法:

用npm安装anywhere。

数据通信需要服务器环境,所以需要搭建本地服务器,iis, apache, 或者如果你装了node环境,可以使用anywhere模块。

只要在cmd中输入npm install anywhere -g. 然后cd+工程名, 输入anywhere 就可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐