I am very new to jQuery/AJAX and I am looking for help. This is the relevant code-snippet:
$(function () {
$('.button').on('click', function (event) {
event.preventDefault(); //prevents page from refreshing
$.ajax({
type: 'POST',
url: 'test2.php',
data: ?????
success: function (data) {
alert('form was submitted');
$('.text').html(data);
}
});
});
});
So, the data I want to pass is for one data: $('#form').serialize(),
and for the other data: { test : test.name },
Basically I want to send a whole form and another parameter. How do I correctly express my wishes to jQuery?
I have tried the following options and they did not work:
$.ajax({
type: 'POST',
url: 'test2.php',
data: $('#form').serialize(), data: { test : test.name },
success: function (data) {
alert('form was submitted');
$('.text').html(data);
}
});
and
$.ajax({
type: 'POST',
url: 'test2.php',
data: $('#form').serialize(), { test : test.name },
success: function (data) {
alert('form was submitted');
$('.text').html(data);
}
});
and
$.ajax({
type: 'POST',
url: 'test2.php',
data: $('#form').serialize()
});
$.ajax({
type: 'POST',
url: 'test2.php',
data: { test : test.name },
success: function (data) {
alert('form was submitted');
$('.text').html(data);
}
});
The php document basically just echos out said data.
Help a newbie out!