$.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'])
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With