我没有 jconfirm 的上传过程运行良好,但是当我需要使用jconfirm 库上传文件时,它总是说undefined index: myfile
.
这是我的代码
function upload() {
// body...
$.confirm({
title:'Upload Dental Form',
type:'green',
theme:'material',
content: '<form method="post" id="myform" enctype="multipart/form-data">'
+'<label for="file" id="up"><h3>Select Dental Form</h3></label> <br><br>'
+'<input accept="image/*" type="file" name="myfile" id="myfile" '
+' /> '
+'</form>',
buttons: {
save: {
text:'save',
btnClas: 'btn-blue',
action:function() {
$.ajax({
url:"<?php echo base_url(); ?>Dental/form_upload",
//base_url() = http://localhost/tutorial/codeigniter
method:"POST",
data: $('form').serialize(),
contentType: false,
cache: false,
processData:false,
success:function(data)
{
alert(data);
}
});
}
},
cancel:function() {
}
},
onContentReady: function () {
// bind to events
var jc = this;
this.$content.find('form').on('submit', function (e) {
// if the user submits the form by pressing enter in the field.
e.preventDefault();
jc.$$save.trigger('click'); // reference the button and click it
});
}
});
}
在我的控制器中
function form_upload()
{
echo json_encode(print_r($_FILES["myfile"]["name"]));
}
我只是出于调试目的而回显。
回应是undefined index: myfile
。为什么我会收到此错误?我尝试过使用new formData(this)
而不是,$('form').serialize()
但它也不起作用。