简体   繁体   English

Codeigniter 2.1,Jquery-500内部服务器错误

[英]Codeigniter 2.1, Jquery - 500 Internal Server Error

I am experiencing 500 Internal Server Error when I try to reach global_info controller via JQ $.post function, and this is happening only with this function. 当我尝试通过JQ $ .post函数访问global_info控制器时遇到500内部服务器错误,并且仅在此函数中发生。

CI controller code: CI控制器代码:

function gi_get_ad_payment_code()
        {
            $q = $this->db->get_where('code_payment', array('code' => $_POST['code']));
            if ($q->num_rows() == 0 ){
                show_error('Whoops, no results :(');
            } else
            {
                 $q = $q->row();
                 echo $time = substr($q->code, 12, 2);
            }

JQ code: JQ代码:

var forma = $('form#mali_oglas'),
pomoc = $('div[role=pomoc]'),
div = $('.mali_oglas_pomoc'),
input = forma.find('input, textarea'),
code = forma.find('#code'),
cct = $.cookie('csrf_token_name');

code.on('focusout', function(){
    var url = '<?php echo base_url() ?>global_info/gi_get_ad_payment_code',
    data = $(this).val();
    $.post(url, {code : data, 'csrf_token_name': cct}, function(){
        console.log(code);
        $('.mali_oglas_img_paid').slideDown('slow');
        code.after('<input type="hidden" name="time" value="'+ data +'" />');
        code.after('<input type="hidden" name="paid" value="1" />');
    });
});

When I try some other controllers, this is working fine (I also use $.post in other places with controllers that are not global_info and everything is working fine). 当我尝试其他一些控制器时,这可以正常工作(我在其他地方使用$ .post的控制器不是global_info,并且一切正常。) What seems to be the problem here? 这里似乎是什么问题?

I once had this also with CI and basically it had something to do with the encoding of the controller file (UTF-8, ANSI, ...). 我曾经在CI上也遇到过这个问题,基本上它与控制器文件的编码(UTF-8,ANSI等)有关。 I also recreated the controller which solved my problems. 我还重新创建了解决我问题的控制器。

By the way, a neater way of making your URL in your view is <?php echo base_url('global_info/gi_get_ad_payment_code'); ?> 顺便说一句,在视图中创建URL的更整洁的方法是<?php echo base_url('global_info/gi_get_ad_payment_code'); ?> <?php echo base_url('global_info/gi_get_ad_payment_code'); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM