Skip to content
Advertisement

How to use $_FILES in a Jquery/Ajax script to stay on the previous HTML page and upload a file into a folder

I have a php script that uploads a file into a folder :

JavaScript

This works fine, don’t mind the fact that i don’t test if the files exist or other test, it is just to see how uploading a file works.

I also did a script using Ajax to avoid the php file to be loaded and then redirect to my homepage.

JavaScript

These two codes seems to work fine independently but when i combine them the file that i need to upload is not uploaded.

Here is my html code

JavaScript

Advertisement

Answer

Instead of serialize() use FormData()

JavaScript

See for more details – Uploading both data and files in one form using Ajax?

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement