doulin4844 2016-09-26 08:51
浏览 272

ajax中的where子句调用daterangepicker

THE HTML code

  <div class="col-md-4 input-group input-group-lg search">
     <span class="input-group-addon"><i class="fa fa-fw fa fa-calendar red"></i></span>
     <input id="config" class="form-control placeholded" placeholder="Select the date to filter records" type="text" data-cid="<? echo $cid; ?>">
   </div>

THE SCRIPT code how to put the current client id here?

   $(document).ready(function() {

    $('.search i').click(function() {
      $(this).parent().find('input').click();
    });
    updateConfig();

    function updateConfig() {
      var options = {};
      // remove other code for space
      $('#config').daterangepicker(options, function(start, end, label) { 
      var startDate = start.format('YYYY-MM-DD'); var endDate = end.format('YYYY-MM-DD');
      var cid = $(this).data("cid");
      passDate(startDate,endDate,cid); 
       });

    }

  });

function passDate(startDate,endDate,cid) {
$('.loader').show();
$.ajax({
        type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
        url: 'invoiceresult.php', // the url where we want to POST
        data: 'startDate='+startDate+'&endDate='+endDate+'cid='+cid, // our data object
    })
    // remove for space
}
}

THE PHP this is the WHERE clause

 if((!empty($_POST['startDate'])&&(!empty($_POST['endDate'])))) {   // Check whether the date is empty          
    $startDate = date('Y-m-d',strtotime($_POST['startDate']));
    $endDate = date('Y-m-d',strtotime($_POST['endDate']));
    $cid = $_POST['cid'];
    $sresult = $db->prepare('SELECT * FROM invoice WHERE (invoiceCreated BETWEEN  "'.$startDate.'" and "'.$endDate.'") AND cid=:cidg');  // Execute the query
    $sresult->execute(array(":cidg)=>$cid);
    $num_rows = $sresult->fetchColumn(); //Check whether the result is 0 or greater than 0.
    // remove other code for space

SCREENSHOT enter image description here

with this code the result is "undefined" Hope someone will help. Thanks

  • 写回答

1条回答 默认 最新

  • dougong9987 2016-09-26 10:12
    关注

    Add an data-attribut to one element, e.g. the input#config, with your client_id. Then you can read it in javascript and use it value.

    HTML

    <input id="config" class="form-control placeholded" placeholder="Select the date to filter records" type="text" data-client-id="client_id" />

    JS

    $('#config').daterangepicker(options, function(start, end, label) { var startDate = start.format('YYYY-MM-DD'); var endDate = end.format('YYYY-MM-DD'); passDate(startDate,endDate, document.getELementById("config").getAttribute("data-client-id")); });

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度