$.post('image.php', {
image:form.image.value
}
<form id="form" enctype="multipart/form-data">
<input type="file" id="image" name="image"/>
PHP-> isset($_FILES['file'])
如何使用$.post()
发布 $_FILES
表单标签内?
我还需要包含enctype
或者我是否需要使用 AJAX,我该怎么做?
最佳答案
使用 jQuery 表单插件来 AJAX 提交带有文件的表单。 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();
关于jquery - 如何使用JQuery post方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18127300/