Without using any forms whatsoever, can I just send a file/files from <input type="file">
to 'upload.php' using POST method using jQuery. The input tag is not inside any form tag. It stands individually. So I don't want to use jQuery plugins like 'ajaxForm' or 'ajaxSubmit'.
Step 1: Create HTML Page where to place the HTML Code. Step 2: In the HTML Code Page Bottom(footer)Create Javascript: and put Jquery Code in Script tag. Step 3: Create PHP File and php code copy past.
By using PHP Script we can upload selected file or Image to server without refresh of page. After done uploading selected Image we have also uploaded image on web page without refreshing of page. So this is our simple tutorial on How to Upload Image without using Form Submit in Ajax PHP.
You can use FormData to submit your data by a POST request. Here is a simple example:
var myFormData = new FormData(); myFormData.append('pictureFile', pictureInput.files[0]); $.ajax({ url: 'upload.php', type: 'POST', processData: false, // important contentType: false, // important dataType : 'json', data: myFormData });
You don't have to use a form to make an ajax request, as long as you know your request setting (like url, method and parameters data).
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