简体   繁体   English

Javascript设置src属性获取错误的动态值跨源读取阻塞(CORB)阻止了跨源响应

[英]Javascript setting dynamic values for src attribute getting error Cross-Origin Read Blocking (CORB) blocked cross-origin response

I wanted to pass dynamic value to src attribute of javascript, I tried couple of options but it didn't work. 我想将动态值传递给javascript的src属性,我尝试了几个选项,但它没有用。 I am using plain javascript, not jquery. 我使用普通的javascript,而不是jquery。

These are the ways I tried; 这些是我尝试的方式; 1. 1。

<script>
        var script = document.createElement('script');
        script.src ="some url here";
        script.type="text/javascript";
        document.head.appendChild(script); 
   </script>

Error message: Cross-Origin Read Blocking (CORB) blocked cross-origin response https://same url/ with MIME type text/html. 错误消息:跨源读取阻止(CORB)阻止跨源响应https://相同 url / MIME类型text / html。 See https://www.chromestatus.com/feature/5629709824032768 for more details. 有关详细信息,请参阅https://www.chromestatus.com/feature/5629709824032768

Option 2: 选项2:

<script>
var fileName = "<%=request.getAttribute("someurl here")%>";
document.write("<script type=\"text/javascript\" src=\"" + fileName + "\"><\/script>");
</script>

Error message: A parser-blocking, cross site (ie different eTLD+1) script, https://same url/, is invoked via document.write. 错误消息:通过document.write调用解析器阻塞,跨站点(即不同的eTLD + 1)脚本https:// same url /。 The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. 由于网络连接不良,浏览器可能会在此页面加载或未来页面加载中阻止此脚本的网络请求。 If blocked in this page load, it will be confirmed in a subsequent console message. 如果在此页面加载时被阻止,则将在后续控制台消息中确认。 See https://www.chromestatus.com/feature/5718547946799104 for more details. 有关详细信息,请参阅https://www.chromestatus.com/feature/5718547946799104

The server says the URL points to an HTML document. 服务器说URL指向HTML文档。

Since you are trying to execute it as JavaScript, the browser objects and throws an error message. 由于您尝试将其作为JavaScript执行,因此浏览器会对象并抛出错误消息。

So either: 所以要么:

  • It really it as HTML document and you probably have the wrong URL or 它真的是HTML文档,你可能有错误的URL
  • The server is wrong and you need to fix it to set the correct Content-Type response header ( application/javascript ). 服务器错误,您需要修复它以设置正确的Content-Type响应头( application/javascript )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自 2019 年 3 月 5 日起,跨域读取阻塞 (CORB) 阻止了跨域响应 - Cross-Origin Read Blocking (CORB) blocked cross-origin response since 5th March 2019 ajax发布请求-跨域读取阻止(CORB)阻止了跨源响应CORS - ajax post request - cross-Origin Read Blocking (CORB) blocked cross-origin response CORS 跨域读取阻塞 (CORB) 阻止了跨域响应 - Cross-Origin Read Blocking (CORB) blocked cross-origin response 如何在JS控制台中修复“跨域读取阻止(CORB)阻止跨源响应”? - How to fix “Cross-Origin Read Blocking (CORB) blocked cross-origin response” in the JS console? "如何解决跨域读取阻塞 (CORB) 阻止的跨域响应<URL>" - how to resolve Cross-Origin Read Blocking (CORB) blocked cross-origin response <URL> 跨域读取阻止 (corb) 阻止了 mime 类型 text/html 的跨域响应 - cross-origin read blocking (corb) blocked cross-origin response with mime type text/html 获取 API 跨域读取阻止 (CORB) 阻止了 MIME 类型 text/html 的跨域响应 - Fetch API Cross-Origin Read Blocking (CORB) blocked cross-origin response with MIME type text/html 跨域读取阻塞 (CORB) 阻止跨域响应 https://cdnjs.com/libraries/Chart.js - Cross-Origin Read Blocking (CORB) blocked cross-origin response https://cdnjs.com/libraries/Chart.js 跨域读阻塞 (CORB) - Cross-Origin Read Blocking (CORB) CORB:JSFiddle 上的跨域读取阻塞 - CORB: Cross-Origin Read Blocking on JSFiddle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM