样式复选框和ajax

时间:2017-11-20 18:08:27

标签: javascript php jquery mysql ajax

我正在为评论系统制作一些脚本,幸运的是一切正常,除了在ajax调用期间困扰我的一个小问题。 当我调用使用ajax进行实时数据搜索的页面时,复选框看起来不应该是这样。但是当我输入javascript代码时,复选框看起来应该是这样,但是然后函数没有&#39工作。
这是代码的样子:

Ajax调用

<script>
        $(document).ready(function(){

    load_data('');

    function load_data(query, typehead_search = 'yes')
    {
     $.ajax({
      url:"fetc.php",
      method:"POST",
      data:{query:query, typehead_search:typehead_search},
      success:function(data)
      {
       $('#email_data').html(data);
      }
     });
    }

    $('#email_search').typeahead({
     source: function(query, result){
      $.ajax({
       url:"fetc.php",
       method:"POST",
       data:{query:query},
       dataType:"json",
       success:function(data){
        result($.map(data, function(item){
         return item;
        }));
        load_data(query, 'yes');
       }
      });
     }
    });

 $(document).on('click', 'li', function(){
  var query = $(this).text();
  load_data(query);
 });
});
</script>

执行实时搜索数据的页面

 <?php
require_once("private/initialize.php"); 

//fetch.php
if(isset($_POST["query"])){
 $request = mysqli_real_escape_string($dbc, $_POST["query"]);
 $query = "SELECT * FROM comments WHERE deleted = 2 AND comment_email LIKE '%".$request."%' ORDER BY comment_id DESC";



$result = mysqli_query($dbc, $query);
 $data =array();?>
<?php
 $html = '';
 $html .= '
    <table class="table table-hover table-mail">
                    <tbody>';
 if(mysqli_num_rows($result) > 0){
  while($comment = mysqli_fetch_array($result)){
   $data[] = $comment["comment_title"];
   $data[] = $comment["comment_email"];

   $html .= '
     <tr class="read" id="'.$comment["comment_id"].'">
        <td class="check-mail">
            <input type="checkbox" name="comment_id[]" class="i-checks delete_customer" value="'.$comment["comment_id"].'">
        </td>
        <td class="mail-ontact"><a href="mail_detail.php?comment='.$comment['comment_id'].'">'.$comment['comment_title'].'</a></td>
        <td class="mail-subject"><a href="mail_detail.php?id='.$comment['comment_id'].'">'.$comment['comment_email'].'</a></td>
        <td class=""></td>
        <td class="text-right mail-date">8.22 PM</td>
    </tr>
   ';
  }
 } 
 else{
  $data = 'No Data Found';
  $html .= '
   <tr>
    <td colspan="3">No Data Found</td>
   </tr>
   ';
 }
 $html .= '
     </tbody>
</table>';

 if(isset($_POST['typehead_search']))
 {
  echo $html;
 }
 else
 {
  $data = array_unique($data);
  echo json_encode($data);
 }
}
 ?>
 // the javascript that is making the problem
   <script>
    $(document).ready(function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });
</script>

事先,我非常感谢任何给予的帮助。

1 个答案:

答案 0 :(得分:0)

这就是我不想看的按钮的意思:

这是java脚本代码的样子。 enter image description here

按钮看起来正确,但功能不起作用。但是没有java代码,该函数可以工作,但按钮看起来并不像它们那样。

enter image description here

我希望这个功能都能正常工作,按钮看起来应该是这样的。同时

相关问题