Reputation: 14649
<script>
function showValues() {
var str = $("form").serialize();
$("#results").html(str);
}
$(":checkbox").click(showValues);
$("select").change(showValues);
showValues();
</script>
<form action="this.php" method="get">
<input type="checkbox" name="check" value="$productid" id="ch1"/>
<label for="ch1">check1</label>
</form>
As a checkbox is checked, the serialized URL is displayed on my page. But, as per my understanding of the point of serializing something is to place it into a dynamic url. Can someone give me advice as to how I can send the serialized result to another file via AJAX?
Upvotes: 2
Views: 399
Reputation: 42818
This is the basic usage of serialization and form submition.
var data = $(form).serialize();
$.post('post.php', '&'+data);
Read more more about $.post
at http://api.jquery.com/jQuery.post/#example-3
Also have a look at $.ajax
if you need more control on how you can submit your form. http://api.jquery.com/jQuery.ajax/
Upvotes: 1
Reputation: 56572
You can include your form fields in an AJAX call by using the data
option:
function sendValues() {
var str = $("form").serialize();
$.ajax({
url: "/that.php",
data: str
});
}
You can learn more about AJAX calls in the $.ajax() docs.
Upvotes: 2