2021年3月27日星期六

Get input text /Javascript result using AJAX and PHP

I'm not able to get the value from the input text to output once I change the date. I've tried all sorts of options different values, hard coding etc... Any help would be greatly appreciated .. i know it's probably a small thing i'm missing.

 <?php    error_reporting(0);   $searchquery = trim($_POST['reportrange']);    echo 'result'.$searchquery.'<br><br>';   ?>   <html>   <head>   <title></title>   <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js">.    </script>   <script type="text/javascript"    src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>   <script type="text/javascript"    src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>   <link rel="stylesheet" type="text/css"    href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />   <script type="text/javascript">   $(function() {    var start = moment().subtract(29, 'days');  var end = moment();    function cb(start, end) {      $('#reportrange').html(start.format('MMM D, YYYY') + ' - ' + end.format('MMM D, YYYY'));  }    $('#reportrange').daterangepicker({      startDate: start,      endDate: end,      ranges: {         'Today': [moment(), moment()],         'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],         'Last 7 Days': [moment().subtract(6, 'days'), moment()],         'Last 30 Days': [moment().subtract(29, 'days'), moment()],         'This Month': [moment().startOf('month'), moment().endOf('month')],         'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1,   'month').endOf('month')]      }  }, cb);    cb(start, end);     });  </script>      <script type="text/javascript">   $(document).ready(function () {  $("input").keyup(function () {      $('#results').html('');      var searchString = $("#reportrange").val();      var data = 'reportrange=' + searchString;      if (searchString) {          $.ajax({              type: "POST",              url: 'test.php',              data: data,              dataType: 'text',              async: false,              cache: false,              success: function (result) {                  $('#results').html(result);                 // window.location.reload();                }          });      }     });    });    </script>     </head>     <body>        <input type='text' id="reportrange" name="reportrange" style="background: #fff; cursor:    pointer; padding: 5px 10px; border: 1px solid #ccc; width: 79%">   <br><br>    <div>    <div id="searchresults">Search results :</div>    <ul id="results" class="update">    </ul>    </div>      </body>    </html>  
https://stackoverflow.com/questions/66836906/get-input-text-javascript-result-using-ajax-and-php March 28, 2021 at 06:58AM

没有评论:

发表评论