Reputation: 4061
I have check box and want send value check box (0 or 1) and in entity where clicked check box on some action
<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');
}
});
}
});
in request in action
request = {Symfony\Component\HttpFoundation\ParameterBag} [1]
parameters = {array} [2]
id = "1"
value = "on"
I try like this
event.target.id
"1"
event.target.value
"on"
but why "on" I think can be 1 or 0
how to send data like key(id entity) => value(value check box) ?
Upvotes: 3
Views: 80
Reputation: 48367
In this case you should use a dictionary
and send it to code-behind
.
var dictionary= {};
dictionary[$(this).attr('id')] = $(this).is(":checked")==true? 1:0;
And pass it to ajax
data like this:
data:dictionary
Upvotes: 1
Reputation: 12864
You can create the object to send like this :
var objToSend = {};
objToSend[$(this).attr('id')] = $(this).is(":checked");
And send your data like
data: objToSend
Upvotes: 3