AJAX脚本无法上传文件

时间:2014-11-29 03:59:55

标签: php jquery ajax file-upload

以下是我提交的ajax表单的代码。我已经意识到ajax过去无法上传文件,但现在可以。如何编辑此ajax以允许文件上传?

    <script> 
    $(document).ready(function(){
    $('#status').on('submit',function(e) {

    $.ajax({
    url:'status.php',
    data:$(this).serialize(),
    type:'POST',
    success:function(data){
    console.log(data);
    $("#success").show().fadeOut(5000); //=== Show Success Message==
    $('#statusBox').val("");
    $("#loadViajquery").load("posts.php");
    },
    error:function(data){
    $("#error").show().fadeOut(5000); //===Show Error Message====
    }
    });
    e.preventDefault(); //=== To Avoid Page Refresh and Fire the Event "Click"===
    });
    });
    </script> 
    <span id="error" style="display:none; color:#F00">Uh... something is wrong! Try again :) </span> <span id="success" style="display:none; color:#0C0">Posted!</span>
        <form id="status" method="POST" action="" enctype='multipart/form-data'>
          <textarea id="statusBox" class="form-control input-lg no-border" name="status" rows="2" placeholder="Tell everyone!"></textarea>   
        <footer class="panel-footer bg-light lter">
          <button form="status" class="btn btn-info pull-right">POST</button>
          <ul class="nav nav-pills">
            <label>
                <div>
                   <li><i class="icon-camera"><input class="socialUpload" type="file" name="file" id="file"/></i></li>
                </div>
            </label>         
          </ul>
        </footer>
        </form> 

0 个答案:

没有答案