如何使用FormData上载Ajax文件这是我使用拖放功能动态生成的html。<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>这是我的js密码.。<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);
}
});
}
3 回答
收到一只叮咚
TA贡献1821条经验 获得超4个赞
制剂
var form = $('form')[0]; // You need to use standard javascript object herevar formData = new FormData(form);
var formData = new FormData();formData.append('section', 'general');formData.append('action', 'previewImg'); // Attach fileformData.append('image', $('input[type=file]')[0].files[0]);
发送表格
$.ajax({ url: 'Your url here', data: formData, type: 'POST', contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+) processData: false, // NEEDED, DON'T OMIT THIS // ... Other options like success and etc});
enctype="multipart/form-data"
type:"POST"
注: contentType: false
偶然的你
TA贡献1841条经验 获得超3个赞
$.ajax({ url: 'Your url here', data: formData, type: "POST", //ADDED THIS LINE // THIS MUST BE DONE FOR FILE UPLOADING contentType: false, processData: false, // ... Other options like success and etc})
- 3 回答
- 0 关注
- 502 浏览
添加回答
举报
0/150
提交
取消