CodeIgniter Forums
AJAX in CI3 - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: AJAX in CI3 (/showthread.php?tid=66077)

AJAX in CI3 - Ivo Miranda - 09-02-2016

Is there any special thing about AJAX requests in CI3? We are trying to put all the login system in AJAX and we are getting error 500 through AJAX but no error if not by AJAX.

CSRF is off so it shouldn't be a problem... Or is it? lol

Is there anything else to know about AJAX in CI?

RE: AJAX in CI3 - PaulD - 09-02-2016

I just finished an ajax login with CSRF and it was quite nice, but the next site will go back to a normal separate login page, I think the effort it took was not really worth it. I don't think it improved the user experience significantly.

So I am guessing that your 500 internal error is probably that you have a problem with your code rather than an inherent AJAX or CI problem. Since it is a server side error, it is probably in your controller or a model call. If you are using all the same model calls, probably in your controller. Can you not narrow it down a bit. (First of all, just ajax back a hello world type message. That should work. Then just keep moving that line down the ajax controller code until you get to where the problem occurs.

Hope that helps,


Edit: No, there is nothing special about ajax controllers except that it can be harder to debug and you should echo the responses, not use the normal load->view rendering.

RE: AJAX in CI3 - InsiteFX - 09-02-2016

<!-- jQuery baseUrl -->
        var baseUrl = "<?php echo base_url(); ?>";

You need this line in your html head section to get your sites base url.

    type    : "POST",
    url     : baseUrl + "menu/menuSave",

Then the Ajax url will look like above, "controller/method"

If you miss spell a property in jQuery it can cause it to error on you simple little things.

RE: AJAX in CI3 - rtenny - 09-02-2016

Might also be worth checking the error logs as a Error 500 should get logged.
You might have to switch error logging on in your php.ini

RE: AJAX in CI3 - InsiteFX - 09-03-2016

Error 500 is an Apache server error but certain php code can also cause it.

First I would check the server logs and also use your web browser's Developer tools F12.