如何使用FormData上载Ajax文件
<form method="POST" id="contact" name="13" class="form-horizontal wpc_contact" novalidate="novalidate" enctype="multipart/form-data"><fieldset> <div id="legend" class=""> <legend class="">file demoe 1</legend> <div id="alert-message" class="alert hidden"></div> </div> <div class="control-group"> <!-- Text input--> <label class="control-label" for="input01">Text input</label> <div class="controls"> <input type="text" placeholder="placeholder" class="input-xlarge" name="name"> <p class="help-block" style="display:none;">text_input</p> </div> <div class="control-group"> </div> <label class="control-label">File Button</label> <!-- File Upload --> <div class="controls"> <input class="input-file" id="fileInput" type="file" name="file"> </div> </div> <div class="control-group"> <!-- Button --> <div class="controls"> <button class="btn btn-success">Button</button> </div> </div></fieldset></form>
<script> $('.wpc_contact').submit(function(event){ var formname = $('.wpc_contact').attr('name'); var form = $('.wpc_contact').serialize(); var FormData = new FormData($(form)[1]); $.ajax({ url : '<?php echo plugins_url(); ?>'+'/wpc-contact-form/resources/js/tinymce.php', data : {form:form,formname:formname,ipadd:ipadd,FormData:FormData}, type : 'POST', processData: false, contentType: false, success : function(data){ alert(data); } }); }
收到一只叮咚
偶然的你