获取使用jQuery的ajax提交选中的复选框值和表单输入值表单、复选框、jQuery、ajax

2023-09-10 18:29:32 作者:我的骄傲你知不知道

我实施的appilication其中一个模块包含搜索方法,我们得到的人在表中的列表,这里是code吧。

 <表类=桌桌条纹表边框的表格悬停ID =sample_3>
  < D​​IV CLASS =模式变脸ID =短信的tabindex = -  1角色=对话框中的咏叹调 -  labelledby =myModalLabelARIA隐藏=真>
    < D​​IV CLASS =模式 - 对话>
      < D​​IV CLASS =模式的内容>
        < D​​IV CLASS =模式的首部>
          <按钮式=按钮级=关闭数据解雇=莫代尔ARIA隐藏=真>< /按钮>
          < H4类=模式的标题>撰写SMS< / H4>
        < / DIV>
        < D​​IV CLASS =模态体>
          < D​​IV CLASS =形组>
            <标签>消息< /标签>
            < TextArea类=表单控制行=3NAME =smsmessage>< / textarea的>
          < / DIV>
        < / DIV>
        < D​​IV CLASS =模式躯>
          <按钮式=按钮级=BTN蓝>发短信< /按钮>
          <按钮式=按钮级=BTN默认的数据解雇=模式>关闭< /按钮>
        < / DIV>
      < / DIV>
      &所述;! -  /.modal-content  - >
    < / DIV>
    &所述;! -  /.modal-dialog  - >
  < / DIV>
  < THEAD>
    &其中; TR>
      百分位类=表复选框> <输入类型=复选框级=组可检查的数据集=#sample_3 .checkboxes/>< /第i个
      <第i个姓和LT; /第i个
      百分位>名称< /第i个
      百分位>性别< /第i个
      <第i个城市与LT; /第i个
      <第i个手机号码< /第i个
      百分位>< /第i个
    < / TR>
  < / THEAD>
  < TBODY>

< PHP
  如果($ numRows行!=0){
    而($结果= mysql_fetch_array($查询,MYSQL_ASSOC)){
?>

    < TR类=奇gradeX>
      < TD><输入类型=复选框级=复选框值=< PHP的echo $结果['mobileNo'];?>中NAME =数字/>< / TD>
      < TD>< PHP的echo $结果['姓']; ?>< / TD>
      < TD>< PHP的echo $结果['名称']; ?>< / TD>
      < TD>< PHP的echo $结果['性']; ?>< / TD>
      < TD>< PHP的echo $结果['$ P​​ $ pTown']; ?>< / TD>
      < TD>< PHP的echo $结果['mobileNo']; ?>< / TD>
      < TD>< A HREF =details.php ID =<?PHP的echo $结果['身份证'];?>中类=BTN BTN-XS绿色><我类=发发搜索>< / I>查看< / A>&安培; NBSP;&安培; NBSP;&安培; NBSP;< A HREF =editdetails.php ID =<?PHP的echo $结果['身份证'];?>中类=BTN BTN-XS蓝色><我类=发发编辑>< / I>编辑< / A>&安培; NBSP;&安培; NBSP;&安培; NBSP<一类=的fancybox键fancybox.iframe BTN BTN-XS紫色的href =singlesms.php数=<?PHP的echo $结果[ mobileNo'];?>><我类=发发信封>< / I>发送短信和LT; / A>< / TD>
    < / TR>

< PHP
    }
  } 其他 {
?>

    &其中; TR>
      < TD>没有找到记录< / TD>
      < TD>< / TD>
      < TD>< / TD>
      < TD>< / TD>
      < TD>< / TD>
      < TD>< / TD>
    < / TR>

< PHP
  }
?>

  < / TBODY>
< /表>
 

这是由复选框选中只发送

现在,如果我点击提交按钮,我想这些值。我想复选框值和输入:smsmessage通过jQuery的AJAX发送提交。我实现了一个code,但它只是使用复选框价值观,我想输入值通过AJAX后通过。这里是什么,我已经实现了。

  $('。btnadd)。点击(函数(){
        VAR校验值= $('输入[名称=数字]:检查)。图(函数()
        {
            返回$(这).VAL();
        })。得到();

        $阿贾克斯({
            网址:loadmore.php,
            类型:'后',
            数据:{IDS:校验值},
            成功:功能(数据){

            }
        });
    });
 
jQuery选取所有复选框被选中的值并用Ajax异步提交数据

u能请建议如何发送输入:也smsmessage这个职位的方法。 这里是bulksms.php

  $成功=0;
           $消息= $ _ POST ['smsmessage'];
         如果($消息=)
          {
              回声请提供详细正确;
           }
           的foreach($号$ _ POST ['号'])
               {

$参数['移动电话号码'] = $编号;
$参数['消息'] = $消息;
            如果(api_connect(演示,试玩@ 123,$参数))
                {
                    $成功=1;
                }

               }
         如果($成功==1)
                  {
         回声短信发送给所有选定的人;
           }
 

解决方案

我想看看推值到校验值数组的结尾,像这样:

  $('。btnadd)。点击(函数(){
    VAR校验值= $('输入[名称=数字]:检查)。图(函数(){
        返回$(这).VAL();
    })。得到();

    checkValues​​.push($('输入[名称= smsmessage])VAL());

    $阿贾克斯({
        网址:loadmore.php,
        类型:'后',
        数据:{IDS:校验值},
        成功:功能(数据){}
    });
});
 

或者你也可以在Ajax调用添加另一个数据值:

  $('。btnadd)。点击(函数(){
    VAR校验值= $('输入[名称=数字]:检查)。图(函数(){
        返回$(这).VAL();
    })。得到();

    $阿贾克斯({
        网址:loadmore.php,
        类型:'后',
        数据:{IDS:校验值,smsmessage:$('输入[名称= smsmessage])VAL()},
        成功:功能(数据){}
    });
});
 

  $('。btnadd)。点击(函数(){
        检查= $('输入[名称=数字]:检查);
        如果(checked.length大于0){
            VAR校验值= checked.map(函数(){
                返回$(这).VAL();
            })。得到();

            $阿贾克斯({
                网址:loadmore.php,
                类型:'后',
                数据:{IDS:校验值},
                成功:功能(数据){}
            });
        }其他{
             警报(你需要选择至少一个复选框!);
        }
    });
 

i'm implementing an appilication in which one module contains search method, we get the list of people in table, here is the code for it.

<table class="table table-striped table-bordered table-hover" id="sample_3">
  <div class="modal fade" id="sms" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
          <h4 class="modal-title">Compose Sms</h4>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>Message</label>
            <textarea class="form-control" rows="3" name="smsmessage"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn blue">Send Sms</button>
          <button type="button" class="btn default" data-dismiss="modal">Close</button>
        </div>
      </div>
      <!-- /.modal-content --> 
    </div>
    <!-- /.modal-dialog --> 
  </div>
  <thead>
    <tr>
      <th class="table-checkbox"> <input type="checkbox" class="group-checkable" data-set="#sample_3 .checkboxes"/></th>
      <th>Surname</th>
      <th>Name</th>
      <th>Gender</th>
      <th>Town</th>
      <th>Mobile No</th>
      <th></th>
    </tr>
  </thead>
  <tbody>

<?php 
  if($numrows!= "0") {
    while($result = mysql_fetch_array($query,MYSQL_ASSOC)){
?>

    <tr class="odd gradeX">
      <td><input type="checkbox" class="checkboxes" value="<?php echo $result['mobileNo'];?>" name="numbers"/></td>
      <td><?php echo $result['surname']; ?></td>
      <td><?php echo $result['name']; ?></td>
      <td><?php echo $result['sex']; ?></td>
      <td><?php echo $result['preTown']; ?></td>
      <td><?php echo $result['mobileNo']; ?></td>
      <td><a href="details.php?id=<?php echo $result['id'];?>" class="btn btn-xs green"><i class="fa fa-search"></i> View</a>&nbsp;&nbsp;&nbsp;<a href="editdetails.php?id=<?php echo $result['id'];?>" class="btn btn-xs blue"><i class="fa fa-edit"></i> Edit</a>&nbsp;&nbsp;&nbsp<a class="fancybox-button fancybox.iframe btn btn-xs purple" href="singlesms.php?number=<?php echo $result['mobileNo'];?>"><i class="fa fa-envelope"></i> Send Sms</a></td>
    </tr>

<?php 
    }
  } else { 
?>

    <tr>
      <td>No Records Found</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>

<?php
  }
?>

  </tbody>
</table>

now if i click submit button, i want only those values to be sent which are selected by checkbox. i want the checkbox values and input:smsmessage to be sent through jquery ajax submit. i have implemented a code but it just uses the checkbox values, i want the input value to be passed through ajax post. here is the what i have implemented

    $('.btnadd').click(function(){
        var checkValues = $('input[name=numbers]:checked').map(function()
        {
            return $(this).val();
        }).get();

        $.ajax({
            url: 'loadmore.php',
            type: 'post',
            data: { ids: checkValues },
            success:function(data){

            }
        });
    });

Can u please suggest how to send the input:smsmessage also to this post method. here is the bulksms.php

          $success="0";
           $message=$_POST['smsmessage'];
         if($message="")
          {
              echo "Please Provide Details Correctly";
           }
           foreach($number as $_POST['numbers'])
               {

$parameters['mobilenumber']=$number;
$parameters['message'] = $message;
            if(api_connect("demo","demo@123",$parameters))
                {
                    $success="1";
                }

               }
         if($success=="1")
                  {
         echo "SMS Sent to all selected people";
           }

解决方案

I'd look at pushing the value onto the end of the checkValues array, like this:

$('.btnadd').click(function(){
    var checkValues = $('input[name=numbers]:checked').map(function(){
        return $(this).val();
    }).get();

    checkValues.push( $('input[name=smsmessage]').val() );

    $.ajax({
        url: 'loadmore.php',
        type: 'post',
        data: { ids: checkValues },
        success:function(data){ }
    });
});

Or you could add another data value in the ajax call:

$('.btnadd').click(function(){
    var checkValues = $('input[name=numbers]:checked').map(function(){
        return $(this).val();
    }).get();

    $.ajax({
        url: 'loadmore.php',
        type: 'post',
        data: { ids: checkValues, smsmessage: $('input[name=smsmessage]').val() },
        success:function(data){ }
    });
});

  $('.btnadd').click(function(){
        checked = $('input[name=numbers]:checked');
        if( checked.length > 0 ) {
            var checkValues = checked.map(function(){
                return $(this).val();
            }).get();

            $.ajax({
                url: 'loadmore.php',
                type: 'post',
                data: { ids: checkValues },
                success:function(data){ }
            });
        }else{
             alert("You need to pick at least one checkbox!");
        }
    });