Can ajax success redirect form posted to php directly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can ajax success redirect form posted to php directly

I have a form posted to php file with jquery ajax but i could not get the file type data. So i want to add the php file to the html action like this: <form method='post' action='image.php' enctype="multipart/form-data"> <input type='file' name='image' id='image' > </form> And still use ajax success function to redirect it after post

17th Sep 2020, 6:19 PM
Adetola Adex
Adetola Adex - avatar
2 Answers
+ 1
Yes. Whether your JavaScript-generated HTTP request is uploading a file or not, you can get the same type of data in a response. You can then use the result to decide where to redirect to if something about the URL needs to come from the server. You could run JavaScript like this to perform the redirect: window.location.href = "http://www.w3schools.com"; This isn't what you asked but you can also submit the form using JavaScript and let the server redirect to another page by running something like this in PHP: header('Location: yournewlocation.php'); JavaScript can submit the form without using AJAX. It can be submitted by running something like: document.querySelector('form').submit();
23rd Sep 2020, 12:34 PM
Josh Greig
Josh Greig - avatar
0
Very help ill try using javascript
24th Sep 2020, 7:09 AM
Adetola Adex
Adetola Adex - avatar