M
M
Max Kuznetsov2011-02-11 22:11:20
CodeIgniter
Max Kuznetsov, 2011-02-11 22:11:20

[Solved] CodeIgniter and ajax-post request

Khabrovchane, help me figure it out.

There is a simple form from where information should be sent by ajax.
I try $.get():

$.get('registration/check/', 's=3', function(html) {
   alert('1');
});

Everything is fine.

I try $.post() with the same parameters:

$.post('registration/check/', 's=3', function(html) {
   alert('1');
});

FireBug receives a 500 error in response (internal server error).

Has anyone experienced this?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
R
Renat Ibragimov, 2011-02-11
@MpaK999

Log show what gives?
Also, CodeIgniter is usually configured to cut off GET requests in reverse.
I would write the URI with the root - '/registration/check'
And $.post in JQuery really has the format that the second parameter is not a string, but an object.
And what does it give out?

$.ajax({
  type: 'POST',
  url: '/registration/check',
  data: {s:3}
});
</script>

K
Konstantin Kitmanov, 2011-02-11
@k12th

Another idea: some frameworks (for example, symfony (as far as I know)), if you send post instead of get (or vice versa), it gives 404, not 405 or 406. Maybe something similar in CI?

A
Aragats, 2011-02-11
@Aragats

another stupid idea, and if so:
$.post('registration/check/', {s: "3" }, function(html) {
alert('1');
});

M
Max Kuznetsov, 2011-02-12
@pluseg

Can anyone send the working .htaccess (the one at the root) and configs to the mail? I will be very grateful. (I'll write soap in a personal.)

M
Max Kuznetsov, 2011-02-12
@pluseg

Reinstalled CodeIgniter (v2.0.0), nothing changed. The most interesting thing is that the config seems to be ignored. Change $config['log_threshold'] = 4; and $config['allow_get_array'] = FALSE; doesn't affect anything.

M
Max Kuznetsov, 2011-02-13
@pluseg

Thank you all for your attention, the reason was found - $config['csrf_protection'] = true was included in the config. Figured it out by going through input.class and commenting out $this->_sanitize_globals() first. In the method code, there was a reference just to csrf. True, now it is not clear how to send a post with csrf enabled, but this is already a matter of time;)
Thank you all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question