代码如下
查看
<input type="text" name="name" id="name" class="input_field" />
<input type="file" name="userfile" id='img_upload' />
阿贾克斯代码
dataString = $("#student_info_form").serialize();
$.ajax ({
type : "POST",
url : "<?php echo base_url();?>sms_con/add_student_info",
data : dataString,
cache : false,
success : function(data){
}
});
return false;
控制器代码
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '800';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload("userfile"))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$img = $data ['upload_data']['file_name'];
$data = $this->sms_model->add_student_info($img);
}
但是当我提交表格时,我可以看到错误消息是“您没有选择要上传的文件”;
如何通过 ajax 插入带有上传图片的数据。
请问有什么帮助吗?