javascriptphpjqueryhtmlajax

Html <form> with php and ajax


I would like to know in what way passing data from a form to a php file is best?

I have used ajax to retrieve a page and load into a div tag on the "master page", now there is a form on this sub page that needs to upload a file. So far i have got it to upload and the form posts to a new .php file where the data is handled.

When the data is handled and the page then navigates back to the master page, i noticed upon form submission when it is directed to the new php page, it shows blank white while the code executed and then redirects to the master page, my question is:

In order to eliminate the white page while code is being executed, is there a better way to go about this or is this sufficient and what can i do to not show the white page?

Thanks in advance.

Warren


Solution

  • Why not simply use jQuery. See how they interupt the submit and you may put validations etc. then process then do whatever you need: http://api.jquery.com/submit/

    <form id="target" action="destination.html">
      <input type="text" value="Hello there">
      <input type="submit" value="Go">
    </form>
    <div id="other">
      Trigger the handler
    </div>
    
    $( "#target" ).submit(function( event ) {
      alert( "Handler for .submit() called." );
      event.preventDefault();
    });