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

标签 javascript jquery ajax iframe file-upload

它可以在所有其他浏览器中工作,之前也可以在 IE8 上工作,但我做了一些代码清理并移动了一些东西,现在它将此表单提交给它自己。这是一个“ajax” uploader (是的,不是真正的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 正常工作。另外,我确信它正在提交给它自己,因为 iframe 显示了它自己内部的当前页面,并且所有脚本都会再次加载。另外,在 .live() 中,添加 return false; 不会执行任何操作。

以下是 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>

最佳答案

它应该将表单发送给自己。

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

但是,正如您正确完成的那样,提交处理程序可能会导致表单根本无法提交(我问,首先提交的意义是什么?但这已经过去了)

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

关于javascript - IE8正在将表单提交到当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3630527/

相关文章:

javascript - 使用 AJAX 加载 GZIP JSON 文件

javascript - jquery ajax 回调失败时刷新页面

jquery - 如何只让父div可以点击?

javascript - 尝试设置输入 node.js puppeteer 的值时出现未定义错误

javascript - 记住菜单状态垂直多级导航

jquery - 使用键盘时未触发 <select> 更改事件

javascript - 多次ajax调用jsp片段中包含的js文件

javascript - 我不断收到的控制台警告是什么 - 延迟长时间运行的计时器任务以提高滚动平滑度?

javascript - 在第一个函数之后执行第二个函数 - REST

javascript - 如何在 CSS 圆内显示全尺寸图像?