简体   繁体   English

jQuery,将表单POST / FILES数据传递给PHP

[英]JQuery,Passing Form POST/FILES data to PHP

I have simple Image ulpoad HTML Form, The Idea is, I'm passing my Data to PHP script Via JQuery, Anyway, My script is not passing $_FILES Data Code: 我有一个简单的Image ulpoad HTML表单,其想法是,我正在通过JQuery将数据传递给PHP脚本,无论如何,我的脚本没有传递$ _FILES数据代码:

<script type="text/javascript">
        $(document).ready(function(){
            $('#addpic').live('submit', function(e) {
                e.preventDefault();
                $.post('add.php', $(this).serialize(), function (data, textStatus) {
                    if (data == "true") { //Upload successful
                        $('#submitf').hide();
                        $('#backf').hide();

                        var thank="<br><br><br><center><h3>Teşekkürler,<br>fotoğraf kontrol edildikten sonra aktif hale gelecektir.</h3></center><br><br><br>";
                        $('#signupdiv').html(thank);
                    }
                    else if (data == "err") {

                    }
                     else {
                        alert(data);
                    }
                });
                return false;
            });
        });
</script>

and For Sure my Form is 当然,我的表格是

<form method="POST" action="" name="addpic" id="addpic" onsubmit="return checkform(this);"  enctype="multipart/form-data">

and PHP is simple no problem in there. 而且PHP很简单,没有问题。

You can't upload files using jquery ajax. 您无法使用jquery ajax上传文件。 You can use some available jquery file upload plugins like http://blueimp.github.com/jQuery-File-Upload/ 您可以使用一些可用的jquery文件上传插件,例如http://blueimp.github.com/jQuery-File-Upload/

Google it to get more plugins and use which ever suited with your requirement. Google可以获取更多插件并根据您的需求使用它。

Without full HTML5 support, you cannot effectively upload files using pure AJAX. 没有完整的HTML5支持,您将无法使用纯AJAX有效地上传文件。 There are ways to cheat, however... 有很多作弊的方法,但是...

I answered a very similar question a while back with a little trick I use for non-HTML5 browsers (IE7 and 8) in order to get a file upload going. 不久前,我回答了一个非常类似的问题,并为非HTML5浏览器(IE7和8)使用了一些技巧,以使文件上传得以进行。 It is pretty lightweight and dependencies are light: requires one iframe, and JS. 它非常轻巧,依赖项很轻:需要一个iframe和JS。

The drawback: no statuscode checks are possible. 缺点:无法进行状态码检查。

More info on this answer link: 有关此答案链接的更多信息:

Can I use JavaScript/JQuery to add an uploaded file to Request.Files in ASP.NET? 我可以使用JavaScript / JQuery将上传的文件添加到ASP.NET中的Request.Files吗?

You do not need to search anywhere jQuery.form plugin will do the trick for you. 您无需在任何地方搜索jQuery.form插件即可为您解决问题。

See http://malsup.com/jquery/form/#file-upload 参见http://malsup.com/jquery/form/#file-upload

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

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