weixin_33737134 2017-01-17 12:59 采纳率: 0%
浏览 19

复选框ajax数据

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) ?

  • 写回答

2条回答 默认 最新

  • weixin_33714884 2017-01-17 13:02
    关注

    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
    
    评论

报告相同问题?