我想用笨我尋覓了很多,但找不到解決AJAX上傳圖片。我想用jquery提交表單。下面是我的代碼: 我通過下面的代碼獲得空白值,當我在控制器從視圖中檢索值:無法上傳使用AJAX圖像笨
$file_names=$this->input->post('save_movie123');
查看:
<html>
$(document.body).on('click', '.postbtn' ,function(e){
$('#post_video_255').submit();
});
function sendVideoData()
{
var form = new FormData(document.getElementById("#post_video_255"));
$.ajax({
url: "dashboard/do_upload",
type: 'POST',
data: form,
mimeType:"multipart/form-data",
cache: false,
contentType: false,
processData: false,
success: function(data) {
console.log(data);
alert(data);
},
complete: function(XMLHttpRequest) {
var data = XMLHttpRequest.responseText;
console.log(data);
},
error: function() {
alert("ERROR");
}
}).done(function() {
console.log('Done');
}).fail(function() {
alert("fail!");
});
}
</script>
<form name="post_video" id="post_video_255" method="post" onsubmit="return sendVideoData()">
<span style="margin-left: 8px;">
<input type="file" name="save_movie123" id="movie123" />
<input type="button" class="postbtn" id="submit_movie_289" value="Upload Video File"/>
</form>
</html>
控制器:
function do_upload()
{
$file_names=$this->input->post('save_movie123');
$config['upload_path'] ='./uploads/';
$config['allowed_types'] = 'gif|jpg|png||jpeg';
$config['max_width'] = 1000;
$config['max_height'] = 1000;
$config['max_size'] = 200000;
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
$this->upload->do_upload($file_names);
}
你哈在控制檯中有任何錯誤。 –
@Niranjan N Raju不,我沒有得到任何錯誤螺母ajax錯誤部分執行。 – user3653474