私は修正しようとしているAJAX Postを持っていますが、入力に多数のチェックボックスが付いています。 I「は、今Laravel - AJAX POSTチェックボックスの配列の選択
<script>
$('.modal-footer').on('click', '.sendNotificationNow', function() {
$.ajax({
type:'POST',
url: '/shipments/sendNotifications',
data: {
'billTo': $('.billToEmail:checked').val(),
'shipTo': $('.shipToEmail:checked').val(),
'shipFrom': $('.shipFromEmail:checked').val(),
'_token': $('input[name=_token]').val(),
},
success: function(data) {
$('.errorTitle').addClass('hidden');
$('.errorContent').addClass('hidden');
if ((data.errors)) {
setTimeout(function() {
$('#sentNotifications').modal('show');
toastr.error('Validation error - Check your inputs!', 'Error Alert', {timeOut: 5000});
}, 500);
if (data.errors.title) {
$('.errorTitle').removeClass('hidden');
$('.errorTitle').text(data.errors.title);
}
if (data.errors.content) {
$('.errorContent').removeClass('hidden');
$('.errorContent').text(data.errors.content);
}
} else {
toastr.success('Successfully Sent Notifications!', 'Success Alert', {timeOut: 5000});
$('div.notificationssent').fadeOut();
$('div.notificationssent').load(url, function() {
$('div.notificationssent').fadeIn();
});
}
},
});
});
</script>
:
<input type="checkbox" name="billToEmail[]" value="[email protected]">[email protected]
<input type="checkbox" name="billToEmail[]" value="[email protected]">[email protected]
そして、私は次のスクリプトを起動し、 "通知の送信" というボタンを、しました:現時点では
は、私がこれをしたと言います私の問題がトップの近くに現れていることを確かめてください。そこでは、複数の値をデータ変数に "翻訳"しようとしています。 .val()のほかに何かを置くべきでしょうか?複数のチェックボックスを使って作業する必要があるようなフィールドがもう少しありますが、billToEmailだけでも役立つ場合は、残りの部分を修正できます。
jQueryの '.val()'では、 "一致する要素のセットの最初の要素の現在の値を取得します"と表示されます。 「最初の要素」に注意してください。配列内のすべての値が必要なように思えるので、[この質問](https://stackoverflow.com/questions/786142/how-to-retrieve-checkboxes-values-in-jquery)の回答を確認してください – James