如何将javascript实现到非直接的php页面中

时间:2017-01-31 16:50:05

标签: javascript php

我希望有人在这里帮助我,对我来说这是一个非常大的问题..我想在check_data.php中实现javascript但是这样做不可能因为这个页面没有出现在浏览器中,index.php显示来自check_data.php的表但由于某些原因我需要在check_data.php中实现javascript任何帮助吗?

index.php:

  <input type= "text" name= "datepicker"  id="datepicker" class="form-control" />
   </div>

   <script>
   $('#datepicker').change(function () {

   $.post('check_data.php', {
     dtpickerdate : $(this).val()
   }, function (response) {

    $('table').html(response);

    });

 });

 $("#datepicker").datepicker({dateFormat: "mm-dd-yy",})
                 .datepicker("setDate", new Date()).change();

 </script>

Check_data.php

<table id = "table" class = "table table-bordered">

        <thead class = "alert-info">
         <tr>
                <th>Kitchen Time</th>

                <th>Order#</th>

                <th>First Name</th>
                <th>Last Name</th>
                <th>Address</th>
                <th>Driver#</th>
                <th>Delivery Time</th>
                <th># of People</th>
                <th>Miles</th>
            </tr> </thead><tbody>
  <?php
  $dtpickerdate = isset($_POST['dtpickerdate']) ? 
                        $_POST['dtpickerdate'] : NULL;

 $q_customer = $conn->query("SELECT * from orders inner
                  JOIN customer_order on 
               customer_order.order_no =orders.order_no
               and orders.date like'$dtpickerdate' inner join 
               driver_order  on 
               driver_order.order_no=orders.order_no
               LEFT JOIN customer on 
               customer.phone=customer_order.phone 
               order by k_time,time desc" )
 or die(mysqli_error());

 $k_time = '';
 while($f_customer = $q_customer->fetch_array()){
 $s=mysqli_num_rows($q_customer);
 ?>
  <tr>
 <?php   

    if($k_time == '' || $k_time != $f_customer['k_time']){
     $k_time = $f_customer['k_time'];
     echo '<td align="center" > <span style=" font-weight:bold;">' 
     .$f_customer['k_time']. '</td>';
      } else{
      echo "<td td style=' border: none;'>&nbsp;</td>";
      }
       echo "<td style='background-color: #5f5d5d; ' align='center'  span style='font-weight:bold;'> <a   href = '#' style='color:#ececec;font-weight:bold;' data-toggle = 'modal' data-target = '#action'>".$f_customer['order_no']."</a></td>";

   echo    "<td style='background-color: #5f5d5d;color:#ececec;'>" .$f_customer['first_name']."</td>"; 
  echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['last_name']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['address']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['driver_no']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>".   $f_customer['d_time']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['no_ofppl']."</td>";
}

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试通过ajax将HTML加载到页面中。

您可以尝试jQuery.load()

<强> page.php文件

$('table').load('check_data.php');

编辑:看起来你对JavaScript和PHP之间的区别以及何时/如何使用它们感到困惑。但是,要回答您的问题,您可以将其他JavaScript放入另一个文件中,并加载它。

<强> page.php文件

$('table').load('check_data.php', function() {
    $.getScript('alert.js');
});

<强> alert.js

alert('hi');