Is it possible to push additional values into a seriazlized $_POST array before sending an AJAX request with jQuery?
This is the scenario:
$('#ajax-preview').on('click', function(e) {
e.preventDefault();
var formData = $('#advertiser-edit-form').serialize();
$.ajax({
type: 'post' ,
url: 'ajax-action.php',
data: formData,
success: function(data, status, jqXHR) {
console.log(data);
}
});
});
formData
is a serialized $_POST array from a page with multiple key/value pairs. I need to add another pair programmatically, namely ajax: true
.
I tried to pass this data set to the AJAX:
var previewData = {
formData: $('#advertiser-edit-form').serialize(),
ajax: true
};
Unfortunately, it changes the structure of data that is passed to the PHP script and, in consequence, the data cannot be processed as expected.