简体   繁体   English

CodeIgniter + AJAX内部错误500

[英]CodeIgniter + AJAX Internal Error 500

I'm trying to make a ajax call to one method in my Notification controller. 我正在尝试对我的Notification控制器中的一个方法进行ajax调用。

My method is: 我的方法是:

public function testeAjax()
{
    if($this->chamadaAjax())
        echo 'Ajax';
    else
        echo 'Form';
}

The $this->chamadaAjax() simply perform and $this->input->is_ajax_request() $this->chamadaAjax()简单执行, $this->input->is_ajax_request()

And this is my Ajax call: 这是我的Ajax电话:

$.ajax({
      type: "POST",
      url: '<?php echo base_url(); ?>/office/notificacao/testeAjax',
      success: function(html) {
        alert(html);
      }
    });

I have a form with two buttons, one for form submit and another for ajax request. 我有一个带有两个按钮的表单,一个用于表单提交,另一个用于ajax请求。

The thing is that when I add some data to the ajax like: data: "nome=Gerep", and call it, I receive a Internal Erro 500 事实是,当我向ajax中添加一些数据,例如:data:“ nome = Gerep”并调用它时,我收到一个Internal Erro 500

When I don't send any data, it works, it returns me form when submitted and ajax when I call ajax request. 当我不发送任何数据,它的工作原理,它返回提交和Ajax当我打电话Ajax请求时,我的形成

Any ideas? 有任何想法吗?

EDIT Using FireBug here is what I get: 编辑使用FireBug,这是我得到的:

f.support.ajax.f.ajaxTransport.sendjquery-1.7.1.min.js:4
f.extend.ajaxjquery-1.7.1.min.js:4
testenotificacao:140
(anonymous function)notificacao:113
onclick

Not sure how you managed to bash the server with a CRSF protection but in case you need to share content between domains CORS is the solution you need. 不确定如何通过CRSF保护来管理服务器,但是如果需要在域之间共享内容,则需要使用CORS Just define Origin policies on your web server and you are good to go. 只需在Web服务器上定义Origin策略,您就可以开始了。

Are you passing the data in the URL or defining an object? 您是在URL中传递数据还是在定义对象? Ie: Data being passed (especially POST) should look something like this: 即:正在传递的数据(尤其是POST)应如下所示:

$.ajax({
      type: "POST",
      url: '<?php echo base_url(); ?>/office/notificacao/testeAjax',
      data: { nome: "Gerep" },
      success: function(html) {
        alert(html);
      }
    });

and NOT like this: 而不是这样的:

$.ajax({
      type: "POST",
      url: '<?php echo base_url(); ?>/office/notificacao/testeAjax?nome=Gerep',
      success: function(html) {
        alert(html);
      }
    });

问题出在跨站点请求伪造 ,禁用它可以解决问题。

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

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