$.AjaxFileUpload is not woking in latest version of Chrome Version 83.0.4103.61 (Official Build) (64-bit)($.AjaxFileUpload 在最新版本的 Chrome 版本 83.0.4103.61(官方构建)(64 位)中无法正常工作)

本文介绍了$.AjaxFileUpload 在最新版本的 Chrome 版本 83.0.4103.61(官方构建)(64 位)中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从最新版本的 Chrome 版本 83.0.4103.61 (Official Build) (64-bit)Jquery $.AjaxFileUpload 不起作用,如果有人有想法,请帮助我,此 AJAX 调用在旧版本的 chrome 和其他浏览器(如 firefox 等)中运行良好.只有最新版本的 chrome 才有问题这是代码:

From the latest version of Chrome Version 83.0.4103.61 (Official Build) (64-bit) Jquery $.AjaxFileUpload is not working, Please help me if anyone has idea, This AJAX call is working fine in Older version of chrome and other browsers like firefox etc.. Only issue with the latest version of chrome Here is the Code:

JSP 代码就像

<input type="file" id="fileform-a04d99a8-3cc0-49af-868d-48bdfd26f448" name="files" class="add-attachment-input" style="position: absolute; top: -100000px;" multiple="" >

Javascript:

 $("#fileform-" + code).AjaxFileUpload({
    action: "/claims/post/attachment/",
    onSubmit: function(element, filename) {
            return {jobcode: code};
    },
    onComplete: function(filename, response) {
        mci.claims.handleAttachmentResponse(code, $thisitem, filename, response);
    }
 });

Java代码:

@RequestMapping(value = "/post/attachment/", method = RequestMethod.POST, produces = "text/html")
@ResponseBody
public String addAttachments(@RequestParam("files")
final List<MultipartFile> files, @RequestParam("jobcode") String jobcode)
{
    jobcode = XSSFilterUtil.filter(jobcode);

    final Map<String, String> result = new HashMap<>();
    for (final MultipartFile file : files)
    {
        result.put(file.getOriginalFilename(), claimsFacade.addAttachmentToClaim(file, jobcode));
    }
    return jsonFacade.mapToJsonString(result);
}

推荐答案

还有一个 jQuery 插件依赖于使用 src="javascript:false" 创建一个 iframe,看起来好像 chrome 83 没有'不再喜欢它了(https://github.com/jquery-form/form/问题/571).看起来(根据那里发布的 jsFiddle)chrome 83 在使用该 src 属性值时会阻止调用(我自己已使用 Chrome 83.0.4103.61-1 进行了验证)但如果src 属性值为 about:blank.

There is another jQuery plugin that relied on creating an iframe with src="javascript:false" and it seems like chrome 83 doesn't like it anymore (https://github.com/jquery-form/form/issues/571). It looks like (as per the jsFiddle posted there) chrome 83 block the call when using that src attribute value (I have verified it myself with Chrome 83.0.4103.61-1) but dones't block it if the src attribute value is about:blank.

根据您使用的插件的来源,它会创建一个具有上述 src 属性值的 iframe (https://github.com/davgothic/AjaxFileUpload/blob/master/jquery.ajaxfileupload.js#L99),因此问题.将该行更改为此应该可以解决问题:

As per the source for the plugin you are using, it creates an iframe with the aforementioned src attribute value (https://github.com/davgothic/AjaxFileUpload/blob/master/jquery.ajaxfileupload.js#L99), and thus the issue. Changing that line into this should solve the issue:

.append('<iframe src="about:blank" name="' + id + '" id="' + id + '" style="display: none;"></iframe>');

尽管插件在过去几年没有太大变化(最后一次提交大约是 2 年前),但您可以使用此更改执行 Pull Request.

Although the plugin hasn't changed much in the last few years (last commit was about 2 years ago), you can do a Pull Request with this change.

这篇关于$.AjaxFileUpload 在最新版本的 Chrome 版本 83.0.4103.61(官方构建)(64 位)中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!