Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Submit form (methd post) with jQuery/AJAX

How can I submit my form with AJAX using jQuery?  It must be sent method=post.

This code submits NO data. I want to submit the data in my form using jQuery.  This code submits blank.  While it connects to submit.php, no data is submitted.
<form action="submit.php" method="post">
<p><label for="name"><strong>Name</strong><em class="required"></em></label><span class="transInput"><input type="text" name="name" id="name" class="i1" /></span></p>
<p><label for="email"><strong>Email</strong><em class="required"></em></label><span class="transInput"><input type="text" name="email" id="email" class="i1" /></span><input type="text" name="spmchk" class="spmchk" /></p>
<p><label for="website"><strong>Website</strong></label><span class="transInput"><input type="text" name="website" id="website" class="i1" /></span></p>
<p><label for="comments"><strong>Message</strong><em class="required"></em></p></div><textarea rows="6" cols="55" name="comments" id="comments"></textarea></p>
<p class="submitLeft"><input type="submit" value="submit" class="submitLeftInput" id="submitButton" /></p>
</form> 
 
<script type="text/javascript">
$(document).ready(function() { 
    //if submit button is clicked   
    $('#submitButton').click(function () {           
     $.post('/submit.php');         
    return false; //cancel the submit button default behaviours
    });   
});
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Albert Van Halen
Albert Van Halen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial