When I click submit I'd like all form data to be POSTed to process.php. Then on process.php I want to echo out the POST data and finally replace everything in results div to what was done in process.php.
<script type="text/javascript"> $(document).ready(function(){ $("#myform").submit( function () { $.ajax({ type: "POST", dataType: "html", cache: false, url: "process.php", success: function(data){ $("#results").html(data); } }); return false; }); //$("#myform").submit( function () { //$('#results').html("yay"); //} // }); //} ); }); </script>
<form name="myform" id="myform" action="" method="POST"> <!-- The Name form field --> <label for="name" id="name_label">zoom</label> <input type="text" name="zoom" id="zoom" size="30" value=""/> <br> </select> <!-- The Submit button --> <input type="submit" name="submit" value="Submit"> </form> <!-- FORM END ---------------------------------------- --> <!-- RESULTS START ---------------------------------------- --> <div id="results">nooooooo<?PHP $_SESSION[''] ?><div> <!-- <input type="image" name="mapcoords" border="0" src="mapgen.php"> ---- --> <!-- RESULTS END ---------------------------------------- -->
The jQuery Ajax FormData is a method to setup “multipart/ form-data” and upload on server using XMLHttpRequest. The jQuery Ajax formData is a constructor to interconnect form data with the server using Ajax HTTP request. The jQuery Ajax formData is a function to create form information and work on it.
The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajaxSubmit, gather information from the form element to determine how to manage the submit process.
The jQuery post() method sends asynchronous http POST request to the server to submit the data to the server and get the response. Syntax: $. post(url,[data],[callback],[type]);
You can call $.post
passing form data serialized. like this:
<script type="text/javascript"> $(document).ready(function(){ $("#myform").submit( function () { $.post( 'process.php', $(this).serialize(), function(data){ $("#results").html(data) } ); return false; }); }); </script>
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