weixin_33701294 2017-01-23 08:23 采纳率: 0%
浏览 18

PHP AJAX发布值

how to post value of checkbox when it checked or uncheked

I have Code

    $("#check").click(function(){`var data = {
               kd_material:$("#kd_material").val(),
               check : $(this).val('1') ? $(this).val("1") : $(this).val("0")
              };

   $.ajax({
      type: "POST",
      url : "<?php echo base_url().'ms_select/select_id_material_koreksi_cek'?>",             
      data: data,
      success: function(msg){
         $('#div-gudang').html(msg);
      }
    });
 }); `
  • 写回答

3条回答 默认 最新

  • weixin_33725722 2017-01-23 08:26
    关注

    You can simply use the isChecked property of the checkbox and send it.

    $("#check").click(function(){`var data = {
                       kd_material:$("#kd_material").val(),
                       check : $(this).is(":checked") 
    };
    

    The value true/false would be sent to the server.

    But if you want to send 1/0 you can do it like this.

    check : $(this).is(":checked") ? 1 : 0
    
    评论

报告相同问题?