如何通过AJAX传递隐藏输入的数据: 它不是一种形式,只是一种隐藏的输入。
<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);
},
});
答案 0 :(得分:1)
{'message-ids':$('#message-ids')。val()}
答案 1 :(得分:1)
正如其他人所说,使用
{'message-ids' : $('#message-ids').val()}
解释是,
{'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
答案 2 :(得分:0)
使用以下代码
data:{ yourparameter: $("#message-ids").val()}