简体   繁体   English

选项资源加载失败,仅适用于Chrome浏览器

[英]OPTIONS Resource failed to load, only in chrome

Trying to upload a file to a servlet using following code: 尝试使用以下代码将文件上传到servlet:

    var fd = new FormData();
    fd.append("file", document.getElementById('fileToUpload').files[0]);
    var xhr = new XMLHttpRequest();
    xhr.upload.addEventListener("progress", uploadProgress, false);
    xhr.upload.addEventListener("load", transferComplete, false);
    xhr.addEventListener("error", onError, false);
    xhr.addEventListener("abort", onUploadCanceled, false);

    xhr.open("POST", urlManager.getUploadHandlerUrl());
    xhr.send(fd);

The problem is only in chrome(works in Firefox perfectly), saying that Failed to load the resource and the problem is not consistent. 问题仅在chrome中(在Firefox中完美运行),表示无法加载资源且问题不一致。 It uploads once or twice at times starts shouting. 上传一次或两次,有时会开始大喊。 When this is the error it doesnot even make call to the server. 当这是错误时,它甚至不会调用服务器。

Tried using jquery from the sample in this quesion . 此问题中使用来自示例的jquery进行了尝试。 But no benefit. 但是没有好处。

I could not figure how something like this can happen. 我不知道这种事情会如何发生。 I appreciate any leads, thanks. 我感谢任何潜在客户,谢谢。

在此处输入图片说明

EDIT: When I wrapped my XHR and explicitly set asynchronous as told in another SO answer , it is working for atleast 3-4 uploads and starting to shout.(a bit better than earlier). 编辑:当我包装XHR并按照另一个SO答案中的说明明确设置异步时,它正在处理至少3-4次上载并开始大喊大叫(比以前好一点)。 I am doubtful whether it had a effect for real. 我怀疑这是否真正有效。
When the state change is happened I am logging the ready state and status. 状态更改发生时,我正在记录就绪状态和状态。 The readyState just jumps from 1 to 4 and the status is left with 0. readyState将从1跳到4,状态保留为0。

I also had similar problem, my problem was solved by solving HTTP vs HTTPS conflict. 我也有类似的问题,我的问题是通过解决HTTP与HTTPS冲突解决的。

if the page that uploads the file is served from HTTP and post request that you are making is HTTPS then it may give "resource failed to load" error in chrome, thats what was happening in my case. 如果上传文件的页面是通过HTTP提供的,而您发出的发布请求是HTTPS,那么它可能会在Chrome中显示“资源加载失败”错误,这就是我的情况。

Page served and Post request both should be HTTP or both should be HTTPS , it can be combination of both. 页面服务和发布请求都应为HTTP或两者均应为HTTPS,可以将两者组合。

I made both HTTP and my problem was solved. 我既做了HTTP又解决了我的问题。 Let me know if that solved your problem as well .best luck. 让我知道这是否也解决了您的问题。祝您好运。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM