CodeIgniter Forums
Links, Controllers in CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Links, Controllers in CodeIgniter (/showthread.php?tid=59957)



Links, Controllers in CodeIgniter - El Forum - 12-16-2013

[eluser]Unknown[/eluser]
I'm starting with CI and I need some help. I'm trying to load some html pages with Ajax, this html files are stored in view folder, and I'm trying to acess this files using a controller and I have no success until now. I want to know, how I can acess this files and if the controller that i'm using it's correct or there is way better to do it.

Controller

Code:
class Router extends CI_Controller
{
     public function index($file)
     {
           $this->load->view($file);
     }
}

Ajax

Code:
var SampleFunction = function (router) {//router is my base_url() + '/router'
    var pageContentBody = $('.page-content .page-content-body');

    if ($("#startLoadTag")){
        $.ajax({
            type: "post",
            cache: false,
            url: router + '/SampleLink.html',
            dataType: "html",
            success: function (html) {
                pageContentBody.html(html);
            }
        });
    }
}

Until now I just get 404 not found.


Links, Controllers in CodeIgniter - El Forum - 12-26-2013

[eluser]InsiteFX[/eluser]
If you take a look at the ,htaccess file in the ./application folder you will see why



Links, Controllers in CodeIgniter - El Forum - 12-26-2013

[eluser]CroNiX[/eluser]
change your function name from "index" to "view" (or anything other than "index"), and change the url in your js to:
Code:
url: router + '/view/SampleLink', //remove .html here

Also, change your actual filename to SampleLink.php instead of SampleLink.html in your /views dir



Links, Controllers in CodeIgniter - El Forum - 12-28-2013

[eluser]mackski[/eluser]
I would make sure all the pages you want to call via AJAX work as per normal, manually accessed.
If you really need to you can test your URLS by hard coding them in your ajax call like:

Code:
if ($("#startLoadTag")){
        $.ajax({
            type: "post",
            cache: false,
            //url: router + '/SampleLink.html',
            url: "http://www.domain.com/index.php/controller/method/var1",
            dataType: "html",
            success: function (html) {
                pageContentBody.html(html);
            }
        });
    }