I'm trying to send serialized data with ajax post and some additional data. I tried the following way:
$("#prw").on('click', function(e){
var url = window.location.origin + "/newsletter/preview";
var title = $('#title').val();
var intro = $('#intro').val();
var array = table.$('input[type="checkbox"], input[type="text"]').serialize() + "&title=" + title + "&intro=" + intro;
$.ajax({
type: "POST",
url: url,
data: array
}).done(function(data){
console.log("Response", data);
});
e.preventDefault();
});
But it only shows checkbox and text, not title and intro in the response. I have also tried this method:
$("#prw").on('click', function(e){
var url = window.location.origin + "/newsletter/preview";
var title = $('#title').val();
var intro = $('#intro').val();
var array = table.$('input[type="checkbox"], input[type="text"]').serializeArray();
array.push({name: 'title', value: title});
array.push({name: 'intro', value: intro});
$.ajax({
type: "POST",
url: url,
data: array
}).done(function(data){
console.log("Response", data);
});
e.preventDefault();
});
It doesn't work either. This url goes to CodeIgniter controller:
function preview() {
$post = $this->input->post();
print_r($_POST);
return $post;
}