【问题标题】:Upload image with jquery and display results用jquery上传图片并显示结果
【发布时间】:2011-08-15 14:28:25
【问题描述】:

我知道这是一个典型的问题,但我已经尝试了很多东西,但还没有让它起作用。我有一个要上传图像的表单,并且据我了解,jquery 本机不支持表单提交中的图像上传。所以我们从我拥有的 html 开始:

<form action="uploadImage.php" method="post" enctype="multipart/form-data" id="image_form" name="image_form">                                                                                                           

<input type="file" name="addImage"  />                                                      

<input type="submit" name="submit" value="submit" />    

                                    </form> 
<div id="results">
</div>

然后我们有了javascript:

$(document).ready(function() {

                                        $('#image_form').submit(function() { // catch the form's submit event
                                            $.ajax({ // create an AJAX call...
                                                data: $(this).serialize(), // get the form data
                                                type: $(this).attr('method'), // GET or POST
                                                url: $(this).attr('action'), // the file to call
                                                success: function(response) { // on success..
                                                    $('#results').load('Images.php'); // update the DIV
                                                }
                                            });
                                            return false; // cancel original event to prevent form submitting
                                        });
                                        });

有些东西告诉我我需要一个 http://malsup.com/jquery/ 的实现,但我真的不明白怎么做。我的图片上传 php 脚本运行良好而且很棒,所以如果我可以使用表单操作但使用 jquery 提交它会很酷。

最好的问候

【问题讨论】:

    标签: php jquery file-upload


    【解决方案1】:

    您不能序列化文件输入。要异步上传某些内容并使其在所有浏览器中工作,您需要使用隐藏 iframe 技巧。我建议为此找到一个 jQuery 插件。 Here is one you can try.

    【讨论】:

      【解决方案2】:

      我建议你使用一些像uploadify 这样的插件。

      【讨论】:

      • 在 2011 年 7 月 1 日至 2011 年 7 月 11 日期间下载 Uploadify 的任何人都需要重新下载 zip 包。一些用户告诉我,一些黑客能够用一些粗略的代码修改我的下载包。基本上,他们在uploadify.php 文件的底部添加了一行代码,可以通过电子邮件发送[...] (uploadify.com/news/security-warning)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 2011-10-17
      • 2012-09-06
      • 2012-09-09
      • 1970-01-01
      • 2020-12-09
      相关资源
      最近更新 更多