Welcome Guest, Not a member yet? Register   Sign In
can't load controller with load function on jquery
#1

[eluser]ardlian.net[/eluser]
i use this code of my controller main with method load
Code:
function load(){
        $this->load->view("content_load");
    }

and i load this controller with jquery load function
Code:
function load(url,div){
    $(div).load(url);
    $("#loading").ajaxStart(function(){
        $(this).show();
    });
    $("#loading").ajaxStop(function(){
        $(this).hide();
    });
}

and this my code for the view
Code:
<li>
<a href="[removed]void(0)" title="Home" id="load">Load</a>
</li>

and the result is not foun 404

the question is.. wy the controller can't load direcly with load function of jquery function?

couse if i load the view direcly, the page can be loaded with this code
Code:
<li><a href="[removed]void(0)" title="Home" id="load">Load</a></li>

but i think this not MVC based...
ned you advice brother... thx
#2

[eluser]ardlian.net[/eluser]
not yet... Sad
#3

[eluser]mjsilva[/eluser]
Didn't quite get it you, but I belive you are trying to load a view with ajax using jquery.

This is what I would do:

File main_view.php

Code:
&lt;html&gt;
    &lt;head&gt;
        <s.c.r.i.p.t type="text/javascript" src="jquery.js"></s.c.r.i.p.t>
        <s.c.r.i.p.t type="text/javascript">
        
        $("#load_ajax_content_bto").click(function(){
            
            $("#ajax_content_container").load("&lt;?=base_url()?&gt;ajax_example_controler/ajax_load");
            
        });
        </s.c.r.i.p.t>
    &lt;/head&gt;
    &lt;body&gt;
        <a href="#" id="load_ajax_content_bto">Ajax magic - clickme</a>
        <div id="ajax_content_container"></div>
    &lt;/body&gt;
&lt;/html&gt;


File ajax_example_controler.php

Code:
&lt;?php

class Ajax_example_controler extends Controller {
    
    function ajax_load()
    {
        echo $this->load->view("ajax_content_view", '', TRUE);
    }
}
?&gt;

File ajax_content_view.php

Code:
<p>This is going to be loaded using jquery ajax magic<p>


Not tested, errors are expected.

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB