Moshe
Moshe

Reputation: 58077

jQuery to perform ajax request from form upon submission?

What jQuery would I use to (check and then) send the contents of a simple form to a PHP form using AJAX?

The form collects an address and the server will send an email and then confirm the success of the operation.

Upvotes: 0

Views: 152

Answers (2)

Damien-Wright
Damien-Wright

Reputation: 7544

Depending on your needs, the $.ajax() method is a litte more versatile than the $.post()..

You can dynamically define whether or not you want to use the get or post method...

An example from the website below:

$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

where data can be info from your form and msg is the response data from the request :)

To attach to the submit button click event, put the above code within this function:

$('#submitButton').click(function () {
  // AJAX CODE HERE
});

read more here: http://api.jquery.com/jQuery.ajax/

hope that helps :)

Upvotes: 1

Jason Kleban
Jason Kleban

Reputation: 20778

You can use $.post(). Pretty easy, actually.

Upvotes: 0

Related Questions