Welcome Guest, Not a member yet? Register   Sign In
AJAX in CI3
#1

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?
Reply
#2

(This post was last modified: 09-02-2016, 04:47 AM by PaulD.)

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,

Paul.

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.
Reply
#3

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

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

Code:
$.ajax({
    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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

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
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#5

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB