Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery POST form data

Tags:

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 ---------------------------------------- --> 
like image 694
LabRaTT Avatar asked Apr 24 '11 19:04

LabRaTT


People also ask

How can form data be posted using jQuery?

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.

What is ajaxForm in jQuery?

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.

What does jQuery Post do?

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]);


1 Answers

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> 
like image 133
keepitterron Avatar answered Sep 18 '22 07:09

keepitterron