参见英文答案 >
How can I upload files asynchronously?32个
$.post('image.PHP',{
image:form.image.value
}
<form id="form" enctype="multipart/form-data">
<input type="file" id="image" name="image"/>
PHP的> isset($_ FILES [ ‘文件’])
如何使用$.post()在表单标记内发布$_FILES?
我还需要包含enctype吗?
或者我需要使用AJAX,我该怎么做?
解决方法
使用jQuery表单插件向AJAX提交带有文件的表单.
http://malsup.com/jquery/form/
http://malsup.com/jquery/form/
在JS中
$('#form').ajaxSubmit({
success: function(response) {
console.log(response);
}
});
用PHP
// after doing upload work etc
header('Content-type: text/json');
echo json_encode(['message' => 'Some message or param whatever']);
die();
完整的文档和示例:http://malsup.com/jquery/form/#ajaxSubmit