Skip to content Skip to sidebar Skip to footer

Codeigniter And AJAX Retrieving/getting Data From Database Error

I always land into the error function in ajax, what is the problem here? I want to retrieve a img url stored in the database and append it using jquery to show my img gallery. But

Solution 1:

You will land in success function when server answer to you with 2xx http status.
If you always land on error function you have an error in codeigneter.
Try to get http status from you server (browser console will help you) and it will help you to understand where is problem.


Solution 2:

You should create first global variable in footer

var base_url = "<?= base_url(); ?>";

And now you need to use like this

function load_contents(track_page)
    {
        $('#loading').show();
        var ref = new Date(); 
        var url = base_url + "gallery/load_design?=" + ref.getTime();
        $.ajax({
            url:url,
            type:'GET',
            cache: false,
            success:function(result)
            {
                alert("success");
            },
            error:function()
            {
                alert("failed"); //it always show the alert failed.

            }
        });
    }

Post a Comment for "Codeigniter And AJAX Retrieving/getting Data From Database Error"