自己做的一个异步文件上传,在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;
});
});
好无语的问题,大家来帮我看看吧 -_-

解决方案 »

  1.   

    试试这样$(document).ready(function(e) {
        $('#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;
        });
    });
      

  2.   

    这个和我那个没有本质上的区别,数据可以提交,但是无法获取iframe里面的数据
      

  3.   

    src="/cross/cross.php"   //使用相对绝对地址看看,不要使用绝对地址。
      

  4.   


    数据可以提交不就是了么。。
    iframe里要获取啥数据??看上去是没有本质区别。。但是IE下直接append(html)就是有问题
      

  5.   


    我的那个也可以提交,问题是你提交了要根据服务器信息返回状态啊
    和append没有任何关系
      

  6.   

    console.log
    ie下面有这个吗?
    你是什么版本的。你用相对地址吧。
    不要加http://localhost:8080/cross
    试试看吧。
      

  7.   

    <?php
    if(!empty($_FILES))
    {
    echo json_encode($_FILES);
    }
    然后在chrome控制台下就能看到返回结果
      

  8.   

    console.log($($(this).contents().get(0)).find('body').html());//是不是这里?
    console.log($($(this).contents().find('body').html());//试着改这里看看
      

  9.   


    $(this).contents()返回的是个document数组,有可能会有多个的存在,与这个并无关系因为我也试过了.......