Ajax - Submitting form in HTML - redirecting

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have a form in my webpage, The form uploads a file to my server.

currently when the file upload form submits, after the server side finishes saving the image it tries to redirect my webpage to a different page :( (the name of the form action)

is there a way to execute the form without the redirect part? like an ajax call for uploading my image?

thanks.

here is the form:

  <form method="POST" action="/project/upload"
  enctype="multipart/form-data">


   Please select a file to upload : <input type="file" name="file" />
   <input type="submit" value="upload" />
   </form>              

EDIT - Let me try to rephrase it: is it possible to submita form in such a way that it wont change my page or redirect? and is it possible to create a call back when it finishes?

Answers

You can use target="iframeName" on your form to get it to post to an iframe on the page with no reloads occuring. Something a little like this:

<form method="POST" action="/project/upload"
  enctype="multipart/form-data" target="myFrame">

..Form content..

</form>

<iframe name="myFrame" height=0 width=0></iframe>

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/19334246/submitting-form-in-html-redirecting

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils