IE10 ajaxupload iframe.contentDocument对象无法访问
2016-01-21 17:37
211 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/kangzhiwang/article/details/50556699
在IE10中使用ajaxupload.js(不跨域),一直报iframe.contentDocument无法访问。
ajaxupload.js中,_createForm如下:注意
settings.data.ajax_token = 1;为ajax请求,如果出错响应json。否则是html请求,如果出错响应html(error.jsp)
_createForm: function (iframe) { var settings = this._settings; // We can't use the following code in IE6 // var form = document.createElement('form'); // form.setAttribute('method', 'post'); // form.setAttribute('enctype', 'multipart/form-data'); // Because in this case file won't be attached to request var form = toElement('<form method="post" enctype="multipart/form-data"></form>'); form.setAttribute('action', settings.action); form.setAttribute('target', iframe.name); form.style.display = 'none'; document.body.appendChild(form); settings.data.ajax_token = 1; // Create hidden input element for each data key for (var prop in settings.data) { if (settings.data.hasOwnProperty(prop)) { var el = document.createElement("input"); el.setAttribute('type', 'hidden'); el.setAttribute('name', prop); el.setAttribute('value', settings.data[prop]); form.appendChild(el); } } return form; },
ajaxupload.js中,获取Response相应的代码:
_getResponse: function (iframe, file) { // getting response var toDeleteFlag = false, self = this, settings = this._settings; addEvent(iframe, 'load', function () { if ( // For Safari iframe.src == "javascript:'%3Chtml%3E%3C/html%3E';" || // For FF, IE iframe.src == "javascript:'<html></html>';") { // First time around, do not delete. // We reload to blank page, so that reloading main page // does not re-submit the post. if (toDeleteFlag) { // Fix busy state in FF3 setTimeout(function () { removeNode(iframe); }, 0); } return; } var doc = iframe.contentDocument ? iframe.contentDocument : window.frames[iframe.id].document; // fixing Opera 9.26,10.00 if (doc.readyState && doc.readyState != 'complete') .........................
原来是java端设置的HttpServletResponse问题:
原来的java代码:
private void processAjaxError(HttpServletRequest request, HttpServletResponse response, Exception e) { OperInfo operInfo = new OperInfo(); operInfo.setIsOk(false); if (e instanceof BusiException|| e instanceof NoRollBackException) { response.setStatus(500); operInfo.setInfo(e.getMessage()); } else { 3ff7 response.setStatus(500); operInfo.setInfo("系统异常,请联系系统管理员。"); operInfo.setData("detail", ExceptionUtils.getFullStackTrace(e)); logger.error("系统异常", e); } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); try { response.getWriter().println(JSONObject.fromObject(operInfo).toString()); response.getWriter().flush(); response.getWriter().close(); } catch (IOException ex) { throw new RuntimeException(ex); }
重新设置:
**// response.setStatus(400);
response.setContentType(“text/html”);**
改后代码:
private void processAjaxError(HttpServletRequest request, HttpServletResponse response, Exception e) { OperInfo operInfo = new OperInfo(); operInfo.setIsOk(false); if (e instanceof BusiException|| e instanceof NoRollBackException) { // response.setStatus(400); operInfo.setInfo(e.getMessage()); } else { // response.setStatus(500); operInfo.setInfo("系统异常,请联系系统管理员。"); operInfo.setData("detail", ExceptionUtils.getFullStackTrace(e)); logger.error("系统异常", e); } response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); try { response.getWriter().println(JSONObject.fromObject(operInfo).toString()); response.getWriter().flush(); response.getWriter().close(); } catch (IOException ex) { throw new RuntimeException(ex); } }
主要是http协议问题,还不是很懂,先记住了
相关文章推荐
- 不区分不行的弱类型脚本中的有类型对象-iFrame通过document.getElementById方法访问和document.nameIframe的差异
- contentWindow 和contentDocument区别 及iframe访问
- contentWindow 和contentDocument区别 及iframe访问
- Mixed Content混合内容错误 Iframe Http页面无法访问
- IE下因设置document.domain而无法和Iframe通信的解决方法(SCRIPT5: 拒绝访问)[转] 最近在开发SDK的过程中发现IE下有个很怪异的问题:在同一域下,因
- ajaxfileupload IE10 拒绝访问
- AS3 无法访问空对象引用的属性或方法
- JSF简单实例及无法正常访问的解决方法(404和The markup in the document preceding the root element must be well-formed. )
- WPF 委托刷新UI线程(System.InvalidOperationException: '调用线程无法访问此对象,因为另一个线程拥有该对象。')
- WPF中调用线程无法访问此对象,因为另一个线程拥有该对象 的解决方法
- Ajaxfileupload 在IE9下用按钮触发file上传控件,请求无法触发的问题
- 访问action无法实例化对象
- document对象元素访问
- jQuery获取iframe的document对象的方法
- 很经典的问题---在VC++ 2005中fstream对象无法访问中文路径下的文件,包括英文路径下的中文名文件。
- 使用ajaxfileupload.js上传无法进回调问题终极解决
- c#重新打开子窗体出现无法访问已释放对象的异常
- IFrame 系列4 ---- document.selection 全方位兼容解析以及TextRange[createTextRange,createRange]对象的深入解析
- 解决:javah 无法访问引用Android对象的问题
- WPF:解决 调用线程无法访问此对象,因为另一个线程拥有该对象。问题