2018-05-24 05:20
浏览 414


I have following PHP while loop which is showing data as the checkbox. The checkbox can be multiple or one.

$supplier = new Admin;
$supplier->rowQuery("SELECT * FROM supplier");

echo '<form id="formId">';
    while ( $data = $supplier->result->fetch_assoc()) {        

        $sid          =  (int) $data['sid'];
        $supplierName = output($data['supplierName']);

        echo '<label class="checkbox-inline">';
            echo "<input type='checkbox' name='sid[]' data-sid='$sid' value='$sid' class='supplierClass'> $supplierName";
        echo '</label>';
echo '<input type="hidden" name="submit" value="supplier" class="clickBtn">';
echo '</form>';

Now I want to call Ajax when at least one checkbox or multiple checkbox is checked. So to do that I have following Javascrpt:

$('.supplierClass').click(function() {
var sid = $(this).data('sid');
   // $("input[type=submit]").trigger(".clickBtn");
   $('#formId').submit(function() {
        url         :   'process/get-vehicle.php',
        type        :   'POST',
        dataType    :   'html',
        data        :   {
          sid   :  sid,
        beforeSend  :   function () {
            $('.allVehicle').html('Please wait...');
        success     :   function ( result ) {

but it's not called the Ajax :(

Overall Goal

You can see that I have set the checkbox name as array sid[]. Becuase I need to get all checkbox checked data as array in a PHP file.

So how can I call Ajax when one or multiple checkboxes are checked? Please note that: In PHP file I want to get all checkbox or one checkbox value.

My Thought:

I think there should be a submit button as hidden. When I click on any checkbox It's should press the hidden button by jQuery to call the Ajax.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题