ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to use jquery .load function in codeigniter?

June 17, 2011 8:15am

Subscribe [4]
  • #1 / Jun 17, 2011 8:15am

    Siyavash

    7 posts

    the title describes what Im searching for:
    Is there any way I can use .load() function of JQUERY ?
    It is not working at all!

    I tried this line of code but it did not respond :

    $('#content').load("<?php echo site_url('main_index/load_view'); ?>");

    and this is my load_view function inside my default controller (main_index) :

    function load_view()
        {            
                $this->load->view('register_admin_view');    
        }
  • #2 / Jun 17, 2011 8:19am

    marjune

    75 posts

    $('#content').load("<?php echo base_url().'index.php/main_index/load_view' ?>");
  • #3 / Jun 17, 2011 9:12am

    Siyavash

    7 posts

    this was not the answer!
    It seems that there should be a special way of using .load() function of jquery in CI!

  • #4 / Jun 17, 2011 9:14am

    marjune

    75 posts

    what do you want to do with your load function then?

  • #5 / Jun 17, 2011 9:17am

    Siyavash

    7 posts

    The exact thing that I want to do is :
    Load a .php file from my views folder into a div tag. thats all !
    ps : it doesnt differ using .load or .html or .ajax or .append… I just want to load a .php view in a div tag.

  • #6 / Jun 17, 2011 9:23am

    marjune

    75 posts

    alright

    $('#content').load("<?php echo base_url().'index.php/main_index/load_view' ?>"); 
      
    
    <div id = "content">
    
    </div>
  • #7 / Jun 17, 2011 9:28am

    Siyavash

    7 posts

    Not Working.
    :(

  • #8 / Jun 17, 2011 9:32am

    Siyavash

    7 posts

    BTW may a view file be loaded directly , not by a controller ?
    I am trying to load a view from a load_view function in my controller and I think some error is raising just there .

  • #9 / Jun 17, 2011 11:43am

    Seb

    35 posts

    The view files are only to be used by controllers.

    However, your “load” with jQuery as mentioned in your first post should be working.

    First try to get in your browser the URL “main_index/load_view”, and then check if everything works as expected or fix any error.

  • #10 / Jun 17, 2011 11:58am

    Siyavash

    7 posts

    thanks for your replies.
    I solved the problem. It was a little mistake of my controller code.

  • #11 / Jun 18, 2011 9:04am

    GreatSlovakia

    13 posts

    Just some notes:
    - @marjune: You should never use base_url() + the url, because then you might get into problems depending on your syntax (e.g. index.php might or might not be there) and is a sign of really poor code.
    - And secondly, if you’re using ajax always use firebug or the chrome developer tools (F12 on windows… I think…) to check the network tab and observe which file is loaded and what it exactly gives back (e.g. a 404)

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases