jQuery $.submit 和文件在 IE 和 FF 中不起作用


jQuery $.submit and files not working in IE and FF

<?php
    if (!empty($_FILES)){
        echo "<pre>";
        echo $_FILES['file']['type'];
        echo "</pre>";
        return;
    }
?>
<script type="text/javascript">
    function autoUpLoad(){
        $("#txtHint").html("<center><img src='include/images/loader.gif' />Reading selected file...</center>");
        $(document).ready(function(){
            $("#file").change(function(){
                $("#myForm").submit(function(data){
                    $("#txtHint").html(data);
                });
            });
        });
    }
</script>
<form id="myForm" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id = "file" onchange='autoUpLoad()'/>
    <input type="submit" value="Send" />
</form>
<div id="txtHint">
    test
</div>

上面的代码不起作用,我不确定这里出了什么问题?仅当我删除这些行时,它才有效:

function(data){
    $("#txtHint").html(data);
}

它只是不允许我将数据返回给txtHint.谁能向我解释如何使其工作?

您正在绑定提交事件,而不是触发它。

.submit()以回调为参数的方法用于绑定提交事件,没有参数来触发提交事件。

您应该执行以下操作:

$(document).ready(function () {
    $("#myForm").submit(function (data) {
        $("#txtHint").html(data);
    });
    $("#file").change(function () {
        $("#myForm").submit();
    });
});