简体   繁体   English

jQuery文件上传iframe方法

[英]JQuery file upload iframe method

I'd like to set up a cross-domain file upload solution that is IE8 compatible. 我想设置一个与IE8兼容的跨域文件上传解决方案。 I've been using blueimp's JQuery File Upload plugin with the iframe transport option . 我一直在使用blueimp的JQuery File Upload插件和iframe transport选项

The upload works well, but I'm not able to get the results of the upload from the server side. 上传效果很好,但是我无法从服务器端获取上传结果。 The redirect option to a result.html file for parsing seems like the solution, but the problem is that I will not have access to the server hosting the form to deploy an HTML file. 将选项重定向到result.html文件进行解析似乎是解决方案,但是问题是我无法访问托管该表单的服务器来部署HTML文件。 In this case, is there any other way to retrieve the results of the upload without deploying an HTML file to the origin server? 在这种情况下,是否有其他方法可以在不将HTML文件部署到原始服务器的情况下检索上载的结果?

Inside the javascript file you can add this event listener ( for non-jQuery way see this answer ) 在javascript文件中,您可以添加此事件监听器( 对于非jQuery方式,请参见此答案

$(window).on('message', function(e){
    var data = e.originalEvent.data || e.originalEvent.message;

    data = JSON.parse(data); //only if you did JSON.stringify for the data you sent
    //do what you need with the message you send.
});

Next when the upload is done you can either write this to the page or redirect the iframe to another page that has this content on it. 接下来,完成上传后,您可以将其写入页面,也可以将iframe重定向到上面包含该内容的另一页面。

window.parent.postMessage('File Upload Done', '*');

If you need to send more data to the parent you need to JSON.stringify the content first (old IE and FF don't allow objects, just strings.) 如果您需要向父级发送更多数据,则需要先进行JSON.stringify内容(旧的IE和FF不允许对象,只能是字符串)。

window.parent.postMessage(JSON.stringify({'success': true, 'id': 1942}), '*');

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

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