JQuery fomdata将空数据发送到php文件?
I am trying to upload file through jquery formdata without any form. My problem is that it is not sending any data to php file.
Here is my jquery code
jQuery(document).ready(function() {
jQuery('#e_picture').change(function() {
var file_data = jQuery('#e_picture').prop('files')[0];
var form_data = new FormData();
form_data.append('e_picture', file_data);
form_data.append('e_uid', '3585');
//});
// data: {e_uid: e_uid, e_picture:'23'},
jQuery.ajax({
url: "index.php?option=com_objectified&task=course_reg.addPicture",
type: 'POST',
data: {
form_data
},
processData: false,
contentType: false,
success: function(result) {
alert('This is ' + result); // Here I show onlu e_uid but it alerts blank result
}
});
});
});
Html
<input type="file" class="form-control" name='e_picture' id='e_picture'>
我试图通过jquery formdata上传文件,没有任何形式。 我的问题是它没有向php文件发送任何数据。
Html b> p>
这是我的jquery代码 b> p>
jQuery( 文件).ready(function(){
jQuery('#e_picture')。change(function(){
var file_data = jQuery('#e_picture')。prop('files')[0];
var form_data = new FormData();
form_data.append('e_picture',file_data);
form_data.append('e_uid','3585');
//});
/ / data:{e_uid:e_uid,e_picture:'23'},
jQuery.ajax({
url:“index.php?option = com_objectified&amp; task = course_reg.addPicture”,
type:'POST ',
data:{
form_data
},
processData:false,
contentType:false,
success:function(result){
alert('This is'+ result); // Here 我显示onlu e_uid,但它会提醒空白结果
}
});
});
});
code> pre>
&lt; input type =“file”class =“form- 控制“name ='e_picture'id ='e_picture'&gt;
code> pre>
div>
You are sending the form_data in wrong way
instead of
data: {
form_data
},
just send it like
data: form_data,
ange content type to : contentType: 'multipart/form-data',
jQuery(document).ready(function() {
jQuery('#e_picture').change(function() {
var file_data = jQuery('#e_picture')[0].files;
var form_data = new FormData();
form_data.append("e_picture[]", file_data[0]);
form_data.append('e_uid', '3585');
//});
// data: {e_uid: e_uid, e_picture:'23'},
jQuery.ajax({
url: "index.php?option=com_objectified&task=course_reg.addPicture",
type: 'POST',
data: {
form_data
},
processData: false,
contentType: false,
success: function(result) {
alert('This is ' + result); // Here I show onlu e_uid but it alerts blank result
}
});
});
});