从数据库Ajax列出后如何解码数据库中的数据?

时间:2018-08-30 11:48:05

标签: ajax codeigniter-3

控制器代码-

在上述问题中,首先,我正在将数据加密到学生表中的数据库中,即新学生注册期间。但是,当我使用学生ID,家庭ID搜索时,然后使用Ajax从数据库中获取数据,但是我不明白如何解密姓名列的数据。因为当我使用 $ this-> encrypt-> decode()时,它给了我一个我不知道使用ajax调用从数据库中获取数据时使用的错误。

=

来自数据库的Ajax调用数据:-

    function search_studs_admin() {
    $this->output->set_content_type('application jason');

    //form validation
    $this->form_validation->set_rules('sel_type', 'Search Type', 'required');
    $this->form_validation->set_rules('search_txt', 'Search Keyword', 'required');

    //validation run
    if ($this->form_validation->run() == FALSE) {
        $this->output->set_output(json_encode(['result' => 0, 'error' => $this->form_validation->error_array()]));
        return FALSE;
    }
    $sel_type = $this->input->post('sel_type');
    $search_txt = $this->input->post('search_txt');
    //echo $class;
    if ($sel_type == 'student_id') {
        $res = $this->user_model->get_student(['student_id' => $search_txt, 'status' => 'active']);
    } 

    if ($res) {   
        $this->output->set_output(json_encode(['result' => 1, 'stud_data' => $res, 'all_studs' => count($res)]));
        return FALSE;
    } else {
        $this->output->set_output(json_encode(['result' => 2]));
        return FALSE;
    }
}
 <div class="row">
            <div class="col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading"><h3 class="panel-title">Find from the Database</h3></div>
                    <div class="panel-body text-center">
                        <div id="search_error" style="color: orangered" ></div>
                        <form id="frm_get_studs" name="frm_get_studs" class="form-inline" method="post" action="<?= site_url('user/search_studs_admin'); ?>" >
                            <label>Search using</label>
                            <br/>
                            <div class="form-group">
                                <select id="sel_type" name="sel_type" class="form-control" >
                                    <option value="" >Please Select an option</option>
                                    <option value="student_id" >Student Id</option>
                                    <option value="student_name" >Student Name</option>
                                    <option value="student_nric" >Student NRIC</option>
                                    <option value="family_id" >Family ID</option>
                                </select>
                                <input type="text" id="search_txt" name="search_txt" class="form-control" placeholder="Enter Text"/>
                            </div>
                            <div class="form-group">
                                <button type="submit" class="btn btn-icon waves-effect waves-light btn-primary m-b-5"> <i class="fa  fa-level-down"></i> </button>
                            </div>
                        </form>
                        &nbsp;&nbsp;&nbsp;
                        OR
                        &nbsp;&nbsp;&nbsp;
                        <form class="form-inline" id="frm_get_studs1" name="frm_get_studs1" method="post" action="<?= site_url('user/search_studs1_admin'); ?>">
                            <div class="form-group">
                                <select id="sel_class" name="sel_class" class="form-control">
                                    <option value="">Please select a Class</option>
                                    <?php foreach ($all_classes as $row): ?>
                                        <option value="<?php echo $row['class_id']; ?>"><?php echo $row['class_name']; ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            &nbsp;
                            <div class="form-group">
                                <button type="submit" class="btn btn-icon waves-effect waves-light btn-primary m-b-5"> <i class="fa  fa-level-down"></i> </button>
                            </div>
                        </form>
                    </div><!-- panel-body -->
                </div> <!-- panel -->
            </div> <!-- col-->
        </div>

注意:<script type="text/javascript"> $(function () { $('div.open').hide(); $('div#search_error').hide(); $('form#frm_get_studs').submit(function (e) { e.preventDefault(); $('.remove_a').remove(); var url = $(this).attr('action'); var postData = $(this).serialize(); //console.log('hello1'); $.post(url, postData, function (o) { if (o.result === 1) { $('div#search_error').hide(); $('div.open').show(); var i = 0; var output = ''; //console.log('hello'); output += '<div class="table-responsive remove_a"><table class="table table-small-font table-bordered table-striped">'; output += '<thead><tr><th>Student ID</th><th>Student Name</th><th>Family ID</th><th>Class ID</th><th>Status</th></tr></thead><tbody>'; for (i = 0; i < o.all_studs; i++) { console.log(o.stud_data[i]['name']); //console.log(o.stud_data[i]['br_id']); output += '<tr>'; output += '<th><strong><a href ="<?= site_url('dashboard/search_result') . '/' ?>' + o.stud_data[i]['student_id'] + '" target ="_blank" class = "remove_a">' + o.stud_data[i]['student_id'] + '</a></strong></th>'; output += '<th>' + o.stud_data[i]['name'] + '</th>'; output += '<th>' + o.stud_data[i]['family_id'] + '</th>'; output += '<th>' + o.stud_data[i]['class_id'] + '</th>'; output += '<th>' + o.stud_data[i]['status'] + '</th>'; output += '<th><button class="but_cut" data-bind=' + o.stud_data[i]['student_id'] + '><i class="fa fa-times"></i></button></th>'; output += '</tr>'; } output += '</tbody></table></div>'; $('div#append_here').append(output); } else if (o.result === 0) { $('div#search_error').show(); var output = '<ul class="search_error" >'; for (var key in o.error) { var value = o.error[key]; output += '<li>' + value + '</li>'; } output += '</ul>'; $('div#search_error').html(output); } else { $('div#search_error').show().text('Data not Available'); } }, 'json'); });

0 个答案:

没有答案