簡體   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