简体   繁体   中英

CodeIgniter + AJAX Internal Error 500

I'm trying to make a ajax call to one method in my Notification controller.

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()

And this is my Ajax call:

$.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.

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

When I don't send any data, it works, it returns me form when submitted and ajax when I call ajax request.

Any ideas?

EDIT Using FireBug here is what I get:

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. Just define Origin policies on your web server and you are good to go.

Are you passing the data in the URL or defining an object? Ie: Data being passed (especially POST) should look something like this:

$.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);
      }
    });

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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