PHP + bootstrap modal + jQuery实现页面刷新

来源:互联网 发布:java源代码加密 编辑:程序博客网 时间:2024/05/17 06:01
html部分代码:
<div class="aw-common-form">    <div class="form-inline search-course">        <input type="text" class="form-control course-name" placeholder="请输入课程名称" name="course_name" value="<?php echo $this->course_name; ?>">        <a class="btn btn-info" onclick="search_course(<?php echo $this->uid; ?>, $('.course-name').val());">搜索        </a>    </div>    <table class="table table-striped table-course">        <thead>        <tr class="">            <th><input type="checkbox" class="check-all"></th>            <th><?php _e('编号'); ?></th>            <th><?php _e('课程名称'); ?></th>            <th><?php _e('课程简介'); ?></th>            <th><?php _e('创建时间'); ?></th>            <th><?php _e('完成时间'); ?></th>            <!--<th><?php _e('操作'); ?></th>-->        </tr>        </thead>        <tbody class="course-tbody">        <?php if ($this->course_list) { ?>        <?php $count = 0; ?>        <?php foreach ($this->course_list as $key => $val) { ?>        <?php $count++; ?>        <tr>            <td><input type="checkbox"></td>            <td><?php echo $count; ?></td>            <td><?php echo $val['Name']; ?></td>            <td><?php echo $val['Description']; ?></td>            <td><?php if ($val['CreateTime']) { ?><?php echo date('Y-m-d H:i', strtotime($val['CreateTime'])); ?><?php } ?></td>            <td><?php if ($val['EndDate']) { ?><?php echo date('Y-m-d H:i', strtotime($val['EndDate'])); ?><?php } ?></td>            <!--<td></td>-->        </tr>        <?php } ?>        <?php } else { ?>        <tr>            <td class="text-center" colspan="6">暂无所学课程</td>        </tr>        <?php } ?>        </tbody>    </table></div>
jQuery部分代码:
function search_course(user_id, course_name) {    $.getJSON(G_BASE_URL + '/course/ajax/search_course/', {user_id: user_id, course_name: course_name}, function(json) {        if (json != '') {            var html = "";            var i = 1;            $('.course-tbody tr').remove();            $.each(json, function(index, array) {                html  = "<tr class='course-tr'>";                html += "<td><input type='checkbox'></td>";                html += "<td>" + i + "</td>";                html += "<td>" + array['Name'] + "</td>";                html += "<td>" + array['Description'] + "</td>";                html += "<td>" + array['CreateTime'] + "</td>";                html += "<td>" + array['EndDate'] + "</td>";                html += "</tr>";                //console.log(html);                $('.course-tbody').append(html);                i++;            });        } else {            $('.course-tbody tr').remove();            html  = "<tr>";            html += "<td colspan='6' class='text-center'>未搜索到相应课程</td>";            html += "</tr>";            $('.course-tbody').html(html);        }    });}
PHP部分代码:
public function search_course_action(){   $where = array();   if (intval($_GET['user_id']))   {      $where[] = 'ID IN(SELECT CourseID FROM ' . get_table('sb_learn') . ' WHERE UserID = ' . intval($_GET['user_id']) . ')';   }   if (trim($_GET['course_name']))   {      $where[] = 'Name LIKE \'%' . trim($_GET['course_name']) . '%\'';   }   $course_list = $this->model('course')->fetch_all('sb_course', implode(' AND ', $where));   if ($course_list)   {      foreach ($course_list as $key => $val)      {         $course_list[$key]['CreateTime'] = date('Y-m-d H:i', strtotime($val['CreateTime']));         $course_list[$key]['EndDate'] = date('Y-m-d H:i', strtotime($val['EndDate']));      }   }   echo json_encode($course_list);}

1 0