$.post('image.php', {
image:form.image.value
}
PHP->isset($_FILES['file'])
How to use $.post()
to post $_FILES
inside of form tag?
Do I still need include enctype
or do I need use AJAX, and how can I do that?
Answer
Use jQuery form plugin to AJAX submit the form with files.
http://malsup.com/jquery/form/
In JS
$('#form').ajaxSubmit({
success: function(response) {
console.log(response);
}
});
in PHP
// after doing upload work etc
header('Content-type: text/json');
echo json_encode(['message' => 'Some message or param whatever']);
die();
Full docs and examples: http://malsup.com/jquery/form/#ajaxSubmit
No comments:
Post a Comment