Jquery,php 表单不使用 .submit() 发送帖子数据


Jquery,php form not sending post data with .submit()

我有一个上传页面,其中包含一个不可见的输入,当您单击图片并选择文件后,我希望javascript将表单提交到另一个页面,但在另一页上$_FILES['file']为空

我的上传页面:

形式:

<form style="visibility: hidden;" id="target" method='POST' action="otherpage.php">
            <input type="file" id="file" value="Go" name="file" />
</form>

JavaScript

            function updatebillede() {
                $('input[type="file"]').click();
            };
            $(document).ready(function() {
                $('input[type="file"]').change(function() {
                    var $this = $(this);
                    if ($this.val() != '') {
                        $("#target").submit();
                    } else {
                        alert("Error");
                    }
                });
            });
        </script>

我的另一个页面

<?php print_r($_FILES['file']); ?>

您需要在表单属性中添加enctype='multipart/form-data'