How to pass data of a hidden input through AJAX: It's not a form, just a hidden input.
<input type="hidden" id="message-ids" value="1,2,3,4,5,6,7,8,9,10">
$.ajax({
type: 'POST',
url: 'messages-get-new.php',
data: ??????????
success: function (data) {
console.log('Submission was successful.');
console.log(data);
$container.append(data);
},
error: function (data) {
console.log('An error occurred.');
console.log(data);
},
});
{'message-ids' : $('#message-ids').val()}
use the below code
data:{ yourparameter: $("#message-ids").val()}
As others have said, use
{'message-ids' : $('#message-ids').val()}
The explanation being,
{'message-ids' //this is your key that ties to the value
: $('#message-ids') //this uses JQuery to get the element that has an id of "message-ids"
//The # sign is used to find something with an id that matches what comes after the # sign
.val()} //This simply returns the value of that element