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



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" οnclick="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
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值