Reputation:
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
Upvotes: 1
Views: 3090
Reputation:
The problem was with Cross Site Request Forgery, disabling it solved the problem.
Upvotes: 0
Reputation:
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.
Upvotes: 1
Reputation: 4778
Are you passing the data in the URL or defining an object? I.e: 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);
}
});
Upvotes: 0