繁体   English   中英

IE8正在将表单提交到当前页面

[英]IE8 is submitting the form to the current page

它可以在所有其他浏览器上运行,并且以前可以在IE8上运行,但是我进行了一些代码清除并移动了一些内容,现在它将该表单提交给自己。 这是一个“ ajax”上传器(是的,不是真正的ajax,但是您知道我的意思)

这是JS:

function file_upload($theform,item_id){
    $theform.attr('ACTION','io.cfm?action=updateitemfile&item_id='+item_id);
    if($theform.find('[type=file]').val().length > 0){
        $('iframe').one('load',function(){
            $livepreview.agenda({
                action:'get',
                id:item_id,
                type:'item',
                callback:function(json){
                    $theform.siblings('.upload_output').append('<li style="display:none" class="file-upload"><a target="blank" href="io.cfm?action=getitemfile&item_file_id='+json[0].files.slice(-1)[0].item_file_id+'">'+json[0].files.slice(-1)[0].file_name+'</a> <a style="color:red" title="Delete file?" href="#deletefile-'+json[0].files.slice(-1)[0].item_file_id+'">[X]</a></li>').children('li').fadeIn();
                    $theform.siblings('.upload_output').find('.nofiles').remove();
                }
            });
            //Resets the file input. The only way to get it cross browser compatible as resetting the val to nothing
            //Doesn't work in IE8. It ignores val('') to reset it.
            $theform.append('<input type="reset" style="display:none">').children('[type=reset]').click().remove();
        });
    }
    else{
        $.alert('No file selected');
        return false;
    }
}
/* FILE UPLOAD EVENTS */
//When they select "upload" in the modal
$('.agenda-modal .file_upload').live('submit',function(event){de
    file_upload($('.agenda-modal .file_upload'),$('.agenda-modal').attr('data-defaultitemid'));
});

如果您不知道,则必须使用ACTION才能使Firefox正常运行。 另外,我肯定知道它正在提交给self,因为iframe在其self中显示了当前页面,并且所有脚本都再次加载。 另外,在.live() ,添加return false; .live() 什么也没做。

这是HTML以防万一:

        <label>Add Attachment</label>
        <form class="file_upload" method="post" enctype="multipart/form-data" target="upload_target" action="">
            <input name="binary" id="file" size="27" type="file" /><br />
            <br><input type="submit" name="action" value="Upload" /><br />
            <iframe class="upload_target" name="upload_target" src="" style="display:none"></iframe>
        </form>
        <label>Attachments</label>
        <ul class="upload_output">
        <li class="nofiles">(No Files Added, Yet)</li>
        </ul>

您应该 return false; 在“提交”处理程序的末尾。

嗯-很难理解。 好吧,该<iframe>确切定义是什么? 编辑 -哦,我明白了。

再次编辑 -好的,我意识到我在这方面有点可信度,但是我建议向<iframe>添加一个“ id”属性(以“ upload_target”作为id值)。 我每隔一段时间就会确切地弄清楚“名称”和“ id”中的哪一个是重要的(以及何时/为什么),但是该信息只持续一个小时左右,然后我的大脑就将其消除。 (“重要”是指<iframe>元素。)

应该将表格发送给自己。

考虑该按钮的类型为Submit(即自动提交表单),并且该表单操作为空(即,自行发送)。

但是,按照您的正确操作,提交处理程序可能会导致表单完全不提交(我问,首先提交的目的是什么?但这已经超出了重点)

无论如何,您应该停止事件传播,并在事件处理程序中返回false。

暂无
暂无

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

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