Javascript 仅在 Firefox 上“加载带有源的 <script> 失败”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45879671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Only on Firefox "Loading failed for the <script> with source"
提问by Narek Tootikian
I want to integrate Marketo form with my existing website on yii framework. My code works on all the browsers except Firefox.
我想在 yii 框架上将 Marketo 表单与我现有的网站集成。我的代码适用于除 Firefox 之外的所有浏览器。
Excerpt from my code:
摘自我的代码:
$('#button').click(function () {
var formData = {
'Email': $('#UserInfo_email').val(),
'FirstName': $('#UserInfo_first_name').val(),
'LastName': $('#UserInfo_last_name').val(),
};
MktoForms2.loadForm('//app-ab23.marketo.com', mcId, formId, function (form) {
var myForm = MktoForms2.allForms()[0];
myForm.addHiddenFields(formData);
myForm.onSuccess(function (values, followUpUrl) {
return false;
});
myForm.submit();
});
});
I get error on Firefox only with message
我只在 Firefox 上收到错误消息
Loading failed for the <script> with source “http://app-ab23.marketo.com/index.php/form/getForm?munchkinId=1111&form=1111&url=http%3A%2F%2Fblox.dev%2Fwizard%2Fmap&callback=jQuery110207175825035737486_1503656391790&_=1503656391791”.
other browsers do the job correctly
其他浏览器正确完成工作
note: munchkinId and formId are changed for posting here.
注意:munchkinId 和 formId 已更改以在此处发布。
回答by Didier L
I just had the same issue on an application that is loading a script with a relative path.
我刚刚在使用相对路径加载脚本的应用程序上遇到了同样的问题。
It appeared the script was simply blocked by Adblock Plus.
看来该脚本只是被 Adblock Plus 阻止了。
Try to disable your ad/script blocker(Adblock, uBlock Origin, Privacy Badger…) or relocate the script such that it does not match your ad blocker's rules.
尝试禁用您的广告/脚本拦截器(Adblock、uBlock Origin、Privacy Badger...)或重新定位脚本,使其不符合您的广告拦截器规则。
If you don't have such a plugin installed, try to reproduce the issue while running Firefox in safe mode.
如果您没有安装此类插件,请尝试在安全模式下运行 Firefox 时重现该问题。
- If you cannot reproduce it in safe mode, it means your issue is linked to one of your plugins or settings.
- Otherwise, it might be a different issue. Make sure you have the same error message as in the question. Also look at the network tab of the developer tools to check if your script is listed (reload the page first if needed).
- 如果您无法在安全模式下重现它,则意味着您的问题与您的插件或设置之一有关。
- 否则,它可能是一个不同的问题。确保您收到与问题相同的错误消息。还要查看开发人员工具的网络选项卡,以检查您的脚本是否已列出(如果需要,请先重新加载页面)。
回答by Stuart
I've just had the same issue - for me Privacy Badger on Firefox was the issue - not adblocker. Posting for posterity
我刚刚遇到了同样的问题 - 对我来说,Firefox 上的 Privacy Badger 是问题所在 - 而不是 adblocker。为后人发帖
回答by Christophe Roussy
I noticed that in Firefox this can happen when requests are aborted (switching page or quickly refreshing page), but it is hard to reproduce the error even if I try to.
我注意到在 Firefox 中,当请求中止(切换页面或快速刷新页面)时可能会发生这种情况,但即使我尝试重现错误也很难。
Other possible reasons: certrelated issues and this one talks about blockers(as other answers stated).
回答by Alex Lehmann
I had the same problem (different web app though) with the error message and it turned out to be the MIME-Type for .js files was text/x-jsinstead of application/javascriptdue to a duplicate entry in mime.types on the server that was responsible for serving the js files. It seems that this is happening if the header X-Content-Type-Options: nosniffis set, which makes Firefox (and Chrome) block the content of the js files.
我在错误消息上遇到了同样的问题(尽管是不同的 Web 应用程序),结果是 .js 文件的 MIME-Typetext/x-js而不是application/javascript由于负责提供服务的服务器上的 mime.types 中的重复条目js 文件。如果X-Content-Type-Options: nosniff设置了标头,似乎就会发生这种情况,这使得 Firefox(和 Chrome)阻止了 js 文件的内容。
回答by mopsled
VPNs can sometimes cause this error as well, if they provide some type of auto-blocking. Disabling the VPN worked for my case.
如果 VPN 提供某种类型的自动阻止,有时也会导致此错误。禁用 VPN 对我的情况有效。
回答by mopsled
As suggested above, this could possibly be an issue with your browser extensions. Disable all of your extensions including Adblock, and then try again as the code is loading fine in my browser right now (Google Chrome - latest) so it's probably an issue on your end. Also, have you tried a different browser like shuddersIE if you have it? Adblock is known to conflict with domain names with trackand marketin them as a blanket rule. Try using private browsing modeor safe mode.
如上所述,这可能是您的浏览器扩展程序的问题。禁用包括 Adblock 在内的所有扩展程序,然后重试,因为代码现在可以在我的浏览器中正常加载(Google Chrome - 最新版本),因此这可能是您的问题。另外,如果你有它,你有没有尝试过像颤抖IE这样的不同浏览器?众所周知,Adblock 会与包含track和包含market在其中的域名发生冲突,这是一项总体规则。尝试使用隐私浏览模式或安全模式。
回答by Aziz Saleh
I ran into the same issue (exact error message) and after digging for a couple of hours, I found that the content header needs to be set to application/javascriptinstead of the application/jsonthat I had. After changing that, it now works.
我遇到了同样的问题(确切的错误消息),在挖掘了几个小时后,我发现需要将内容标头设置为application/javascript而不是application/json我拥有的。更改后,它现在可以工作了。
回答by Lando
If the src is https and the certificate has expired -- and even if you've made an exception -- firefox will still display this error message, and you can see the exact reason why if you look at the request under the network tab.
如果 src 是 https 并且证书已经过期——即使你做了一个例外——firefox 仍然会显示这个错误消息,如果你查看网络选项卡下的请求,你可以看到确切的原因。
回答by seeingwithsound
Today I ran into the exact same problem while working on a progressive web app (PWA) page and deleting some cache and service worker data for that page from Firefox. The dev console reported that none of the 4 Javascript files on the page would load anymore. The problem persisted in Safe mode, so it was not an add-on issue. The same script files loaded fine from other web pages on the same website. No amount of clearing the Firefox cache or wiping web page data from Firefox would help, nor would rebooting the Windows 10 PC. Chrome all the time worked fine on the problem page. In the end I did a restore of the entire Firefox profile folder from a day-old backup, and the problem was immediately gone, so it was not a problem with my PWA app. Apparently something in Firefox got corrupted.
今天,我在处理渐进式 Web 应用程序 (PWA) 页面并从 Firefox 中删除该页面的一些缓存和 Service Worker 数据时遇到了完全相同的问题。开发控制台报告说,页面上的 4 个 Javascript 文件都不会再加载了。该问题在安全模式下仍然存在,因此它不是附加问题。从同一网站上的其他网页加载相同的脚本文件。清除 Firefox 缓存或从 Firefox 擦除网页数据无济于事,重启 Windows 10 PC 也无济于事。Chrome 在问题页面上一直运行良好。最后我从一天的备份中恢复了整个 Firefox 配置文件文件夹,问题立即消失了,所以我的 PWA 应用程序没有问题。显然,Firefox 中的某些内容已损坏。
回答by Physics Lover
I had the same issue with firefox, when I searched for a solution I didn't find anything, but then I tried to load the script from a cdn, it worked properly, so I think you should try loading it from a cdn link, I mean if you are trying to load a script that you havn't created. because in my case, when tried to load a script that is mine, it worked and imported successfully, for now I don't know why, but I think there is something in the scripts from network, so just try cdn, you won't lose anything.
我在 firefox 上遇到了同样的问题,当我搜索解决方案时我没有找到任何东西,但后来我尝试从 cdn 加载脚本,它工作正常,所以我认为你应该尝试从 cdn 链接加载它,我的意思是,如果您尝试加载尚未创建的脚本。因为在我的情况下,当我尝试加载我的脚本时,它工作并成功导入,现在我不知道为什么,但我认为网络脚本中有一些东西,所以试试cdn,你不会不会失去任何东西。
I wish it help you.
我希望它能帮助你。

