简体   繁体   English

当我尝试使用ajax时,chrome的控制台显示“资源加载失败”

[英]When I try to use ajax, chrome's console says “”Resource failed to load"

I want to download a javascript file using ajax. 我想使用ajax下载javascript文件。 But I can't do it. 但是我做不到。

Google chrome console says Resource failed to load Google Chrome控制台表示Resource failed to load

Here is my html. 这是我的HTML。 Please check it and give me comments. 请检查并给我评论。

https://www.box.com/s/b2mj0cs7xbdqh8sdrh92 https://www.box.com/s/b2mj0cs7xbdqh8sdrh92

Try doing GET as your request type. 尝试将GET作为您的请求类型。 So your new code would read, 因此,您的新代码将显示为

$.ajax({
    type: "GET",
    url: "jquery.jsPlumb-1.3.16-all-min.js",
    dataType: "script"
    });

Also make sure that jquery.jsPlumb-1.3.16-all-min.js exists in the same directory as index.htm . 还要确保jquery.jsPlumb-1.3.16-all-min.jsindex.htm存在于同一目录中。 This still won't load it directly into the page, but would be able to access the text and then manipulate it however you want. 这仍然不会直接将其加载到页面中,但是可以访问文本,然后根据需要进行操作。

In my opionion, AJax shouldn't be used to download resource files, but rather to communicate with the server from the client. 在我看来,AJax不应用于下载资源文件,而应从客户端与服务器进行通信。 Too many implications in the former. 前者的含义太多。

What is your expected outcome with loading the js file? 加载js文件的预期结果是什么?

If you're really intending on doing this (and I wouldn't suggest it), use jQuery.getScript(): 如果您真的打算这样做(我不建议这样做),请使用jQuery.getScript():

http://api.jquery.com/jQuery.getScript/ http://api.jquery.com/jQuery.getScript/

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

相关问题 在控制台中抑制 Chrome 的“无法加载资源”消息 - Suppress Chrome 'Failed to load resource' messages in console 无法在Chrome中加载资源+ $ .ajax调用 - Failed to load resource + $.ajax call in Chrome 尝试启动React应用程序时,我不断收到“无法加载资源” - I keep getting “Failed to load resource” when I try to start an React app Ajax“无法加载资源” - Ajax “Failed to load resource” 无法在Chrome下加载资源! 目前不工作ajax - Failed to load resource under Chrome! Not work ajax currently 带有JQ的Ajax请求在Chrome中显示错误:“无法加载资源” - Ajax request with JQ gives an error in Chrome: “Failed to load resource” 当我尝试使用 paypal api 访问用户的付款详细信息时,由于权限不足,授权失败 - When I try to access user's payment details with paypal api its says authorisation failed due to insufficient permissions 当我使用blob从ArrayBuffer加载资源时,为什么在Chrome上出现“不允许加载本地资源”错误? - Why I got `Not allowed to load local resource` error on chrome when I use blob to load resource from ArrayBuffer? 无法在ajax调用中加载资源 - Failed to load resource in ajax call 无法在try / catch块中捕获Chrome的“无法加载本地资源”错误 - Cannot catch Chrome's 'Cannot Load Local Resource' error in try/catch block
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM