Probocop
Probocop

Reputation: 10552

Jquery - use form action including the GET variables?

it it possible to get the form action of a GET form on submit including all of the get variables added on the end?

The reason being I want to use AJAX to run the script that the form submits to, and then just display a thank you message.

Upvotes: 0

Views: 162

Answers (2)

jAndy
jAndy

Reputation: 236032

$('form').bind('submit', function(e){
   $.ajax({
      // ...
      data: $(this).serialize(),
      // ...
   });
   e.preventDefault();
});

Upvotes: 0

Matt
Matt

Reputation: 75317

jQuery makes this extremely easy: http://api.jquery.com/serialize/.

$('#your-form').bind('submit', function (event) {
  jQuery.get('your-url.php', $(this).serialize(), function (response) {
    alert("Woo");
  });

  event.preventDefault();
});

Upvotes: 4

Related Questions