私はチェックボックスがあり、値のチェックボックスに送信します(0または1)とアクションチェックボックスAjaxのデータ
request = {Symfony\Component\HttpFoundation\ParameterBag} [1]
parameters = {array} [2]
id = "1"
value = "on"
で何らかのアクション要求で
<input class="searchType" type="checkbox" name="SharingNotification" id={{ taskExecution.id }}>
<label class="searchtype2label">{{ taskExecution.id }}</label>
</input>
$('.searchType').click(function(event) {
if(this.checked){
$.ajax({
type: "POST",
url: '/app_dev.php/api/customer/customers',
data: {
id: event.target.id,
value: event.target.value
},,
success: function(data) {
alert('it worked');
alert(data);
$('#container').html(data);
},
error: function() {
alert('it broke');
},
complete: function() {
alert('it completed');
}
});
}
});
を上のチェックボックスをクリックしたエンティティで私はこの
event.target.id
"1"
event.target.value
"on"
ようにしてみてくださいしかし、「上」と思う理由をすることができ、1または0
キー(IDエンティティ)=>値(値チェックボックス)のようにデータを送信する方法は?
整数に変更するのが暑いですか? –
@ shuba.ivan、これを使う必要があります: 'objToSend [$(this).attr( 'id')] = $(this).is(":checked ")== true? 1:0; ' –
@ R3 ids' => [key => value]のようにリクエストが必要な場合は? –