自己做的一个异步文件上传,在chrome下运行正常,但是在ie下就提示[SCRIPT5: 拒绝访问]$(document).ready(function(e) {
$('#upload').click(function(e){
$('body').append('<iframe name="cIfram" src="http://localhost/cross/cross.php" style="display:none;"></iframe>');
$('body').append('<form style="display:none;" id="form" action="http://localhost/cross/cross.php" method="post" target="cIfram" enctype="multipart/form-data" encoding="multipart/form-data"><input type="file" id="select" name="File"/></form>');
$('#select').change(function(e){
$("iframe[name='cIfram']").load(function(e) {
e.target.contentWindow.document.domain=document.domain='localhost';//这句是查资料说要使用同源策略,但是也没用啊,而且他们本身就是同源
console.log($($(this).contents().get(0)).find('body').html());
});
$('#form').submit();
});
$('#select').click();
return false;
});
});
好无语的问题,大家来帮我看看吧 -_-
$('#upload').click(function(e){
$('body').append('<iframe name="cIfram" src="http://localhost/cross/cross.php" style="display:none;"></iframe>');
$('body').append('<form style="display:none;" id="form" action="http://localhost/cross/cross.php" method="post" target="cIfram" enctype="multipart/form-data" encoding="multipart/form-data"><input type="file" id="select" name="File"/></form>');
$('#select').change(function(e){
$("iframe[name='cIfram']").load(function(e) {
e.target.contentWindow.document.domain=document.domain='localhost';//这句是查资料说要使用同源策略,但是也没用啊,而且他们本身就是同源
console.log($($(this).contents().get(0)).find('body').html());
});
$('#form').submit();
});
$('#select').click();
return false;
});
});
好无语的问题,大家来帮我看看吧 -_-
解决方案 »
- 限制上传图片的大小
- Extjs高手请进!!!如何在表单下面加系统时间。
- 初学,ext tree没显示出来。
- 怎么样让我的div弹出窗口只在登录的时候出现一次。刷新的时候不要出现了。。。
- 求一正则表达式,把一段html中的 非img 和 非链接的的html信息去掉,留下中间的文字内容!
- 在线等。。。。请搞手指教。。关于层。。
- 文本框的值问题 100分 谢谢
- 【求助】js如何做基于DSA算法的数字签名??
- 怎么用for循环获取表里面的数据
- 如何让“设为主页”里的URL根据不同三级域名改变??
- Jquery dialog( 'destroy' ) 后还有缓存?!
- js 删除table中光标上次所在行
$('#upload').click(function(e){
var iframe = document.createElement("iframe");
iframe.setAttribute("id", "cIfram");
iframe.setAttribute("name", "cIfram");
iframe.setAttribute("src", "javascript:false;");
iframe.style.display = "none";
document.body.appendChild(iframe);
var form = document.createElement("form");
form.setAttribute("action", "http://localhost:8080/gtyz/test");
form.setAttribute("target", iframe.name);
form.setAttribute("id", "form");
form.setAttribute("name", "form");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("method", "post");
form.style.display = "none";
document.body.appendChild(form);
var file = document.createElement("input");
file.setAttribute("id", "select");
file.setAttribute("type", "file");
form.appendChild(file);
$('#select').change(function(e){
$('#form').submit();
});
$('#select').click();
return false;
});
});
数据可以提交不就是了么。。
iframe里要获取啥数据??看上去是没有本质区别。。但是IE下直接append(html)就是有问题
我的那个也可以提交,问题是你提交了要根据服务器信息返回状态啊
和append没有任何关系
ie下面有这个吗?
你是什么版本的。你用相对地址吧。
不要加http://localhost:8080/cross
试试看吧。
if(!empty($_FILES))
{
echo json_encode($_FILES);
}
然后在chrome控制台下就能看到返回结果
console.log($($(this).contents().find('body').html());//试着改这里看看
$(this).contents()返回的是个document数组,有可能会有多个的存在,与这个并无关系因为我也试过了.......