duanliao6789 2015-07-16 18:01
浏览 41

带有ajax和codeigniter的错误500

I have a problem with calling ajax on my view on codeigniter website. Ajax is calling method in controller on same project. I have ajax search, which is work correctly. When I chose one of results, he open a new tab and show me a detail information from database. In some cases when I click on some results(I didn't find rule when it will be happening), ajax return me a 500 error, without go into controller method, but when I refresh the page (F5) he shows me a correct result. Did someone have a same problem, or can help me to fix it? Here is my ajax call:

<script>
$(document).ready(function() {
    $.ajax({
        type: 'POST',
        url: '<?=site_url('index/ajax_read_details')?>',
        dataType: 'json',
        cache: false,
        async:true,
        data: {'param':'<?=$selected?>'},
        beforeSend: function (xhr) {
            $('#loading').show();
        },
        success: function (data) {
            $('#loading').hide();
                var details = '<tr>' +
                    '<td>'+data['title']+'</td> '+
                    '<td>'+data['code']+'</td>' +
                    '</tr>';
                $('#data >tbody').append(details);
            })
        },
        error: function(jqXHR, textStatus, errorThrown){
            alert('Error: '+ errorThrown);
        }
    });
});
</script>

I know now that he didn't go into controller method "ajax_read_details" in index controller in case when it give me an 500 error.But when I refresh, he go into that method and do it correctly job. In both cases, he send a same values but in first he didn't return values, after refresh page he give me a values :(

Short controller method is:

public function ajax_read_details()
{
    $param = $this->input->post('param');

    echo json_encode(array('title' => $param, 'code'=>param));
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法