繁体   English   中英

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'

暂无
暂无

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

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