【问题标题】:Post image file failed发布图像文件失败
【发布时间】:2013-12-12 09:44:59
【问题描述】:

我想上传图片,但文件路径上传失败。

我的表格:

<form id="postIdeaForm" method="post" action="ideas.php" enctype="multipart/form-data">
<input name="selector" id="selector" type="file" style="position:absolute;width:200px;height:25px;display:none;" />
<div id="postIdeaBtn" class="alignRight postBtn pointer"><strong>post</strong></div>
</form>

javascript

$('#postIdeaBtn').click( function() {
                $("#postIdeaForm").submit();

            });

             $("#postIdeaForm").validate({
             errorElement:"div",
             rules: {
             dateIdea: "required"
             },
             messages: {
             dateIdea: ""
             },
             submitHandler: function() {
             $.post("ideas.php", $("#postIdeaForm").serialize(), 
             function(data) {
                 if(data == 'Success') {
                     window.location.href='date_ideas';
                 }
                });
            return false;
             }
            });

但是看控制台,发现文件没有发布,是我做错了吗?

【问题讨论】:

    标签: javascript post image-uploading


    【解决方案1】:

    您不能使用ajax 发布文件,您需要使用iframe solution,或者如果您不介意跨浏览器兼容性,请使用FormData

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多