Ajax请求接收html页面作为响应,并且网页上不显示相同的响应:Codeigniter

时间:2015-06-29 11:42:37

标签: javascript php jquery ajax codeigniter

我的代码接受注册号,在数据库中搜索该学生所做的所有交易,并返回学生支付的页面金额。 问题是,即使我得到正确的响应ajax(使用chrome dev工具检查),页面上也没有显示相同的响应。而Response是一个完整的html页面

以下是我的观点:

<div>
        <input type="text" class="regno" name="reg_no">
        <button class="search_student">Search</button>  
</div>
<table>
    <tr> 
     <?php if(!empty($transactions) and isset($transactions)): 
     foreach ($transactions as $key => $row) { ?>
        <td> <?php echo $row->amount_paid; ?> </td>
     <?php } endif;
      ?>
    </tr>
</table>

这是js函数:

$('.search_student').click(function(){
    //e.preventDefault();

    var regno=$(".regno").val();
    //window.alert(regno);
    $.ajax({
        type : "POST",
        url : "students/get_details",
        data : { 'reg_no' : regno }
    }).done(function(){
            //window.alert("Success");
            //location.reload();
    }).fail(function(){
         window.alert("Could not send data to Server.");
    });
});

这是我的控制器:

public function get_details()
    {
        $roll = $this->input->post('reg_no');              
        $data['transactions'] = $this->student_model->get_student_transactions($roll);
        $data['scripts'] = array ('../bootstrap.min.js','../buttons.js');
        $this->_render_page('allotment', $data);
        //$this->details();
        //var_dump($data['transactions']);
    }

该模型工作正常,经过测试和测试。支付的金额出现在ajax响应中(附带截图),但它没有显示在网页上。 提前致谢!! 回复的屏幕截图:http://www.4shared.com/download/twAiI9Odce/upload.jpg?lgfp=3000

1 个答案:

答案 0 :(得分:0)

更改控制器

public function get_details() {
        $roll = $this->input->post('reg_no');
        $data['transactions'] = $this->student_model->get_student_transactions($roll);
        // $data['scripts'] = array ('../bootstrap.min.js','../buttons.js');
        $this->_render_page('allotment', $data);
    }

查看

<table>
    <tr> 
     <?php if(!empty($transactions) and isset($transactions)): 
     foreach ($transactions as $key => $row) { ?>
        <td> <?php echo $row->amount_paid; ?> </td>
     <?php } endif;
      ?>
    </tr>
</table>

AJAX

$('.search_student').click(function () {
        //e.preventDefault();

        var regno = $(".regno").val();
        //window.alert(regno);
        $.ajax({
            type: "POST",
            url: "students/get_details",
            data: {'reg_no': regno}
        }).done(function (data) {
            $('table').html(data)
        }).fail(function () {
            window.alert("Could not send data to Server.");
        });
    });