jquery 第6章 无法用本地服务器调用 $.getScript()方法。

在使用jQuery时,通过$.getScript()加载本地JS文件遇到跨域问题,导致请求被浏览器阻止。错误提示表明,跨源资源共享(CORS)政策仅支持http、data、chrome、chrome-extension和https协议。尝试使用VSCode的Live Server插件和WAMP服务器,发现前两种方法加载JSON和HTML正常,但$.getScript()在Live Server下仍失败。将文件移到WAMP的www目录下,问题解决。疑问在于为何前两种方法在Live Server下能正常工作。
摘要由CSDN通过智能技术生成

 1 $('#dictionary').load('a.html');  方法 ok

2 $.getJSON('b.json',function(data){  方法 ok

3 但是  $.getScript("c.js"); 就不行了,表现为浏览器没反应。

在vscode里面调试,使用配置chrome,在 c.js中加入断点,但无法进入,报错

Access to XMLHttpRequest at 'file:///F:/%E7%BD%91%E8%AF%BE/jQuery%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/Learning%20jQuery%20-%20Fourth%20Edition/Code/Chapter%206/b.json' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
jquery.js:8475
Access to XMLHttpRequest at 'file:///F:/%E7%BD%91%E8%AF%BE/jQuery%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/Learning%20jQuery%20-%20Fourth%20Edition/Code/Chapter%206/c.js?_=1584516787763' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值