Welcome Guest, Not a member yet? Register   Sign In
Links, Controllers in CodeIgniter
#1

[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.
#2

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

[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
#4

[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);
            }
        });
    }




Theme © iAndrew 2016 - Forum software by © MyBB