Create navigation menu jquery method load

1

I'm having some trouble creating a menu where pages are loaded into div .

What happens is that I'm creating an application following the MVC standard, and I do the URL treatments to redirect them, for each controller, I do not know what happens when it loads the page it does not specifically open in div where predefined.

jQuery code:

jQuery(function () {
    jQuery('.ler').click(function () {
        jQuery('#open').load('corpo.php', function (e) {
            e.preventDefault();
        });
    });
})

HTML code:

<ul class="nav navbar-nav side-nav">
    <li class="active"><a href="<?php URL?>dashboard"><i class="fa fa-dashboard"></i> Dashboard</a></li>
    <li><a href="javascript:void(0)" class="ler"><i class="fa fa-bar-chart-o"></i> Categorias</a></li>
    <li><a href="<?php URL?>noticia" class="ler"><i class="fa fa-table"></i> Noticias</a></li>
    <li><a href="<?php URL?>galeria" class="ler"><i class="fa fa-edit"></i> Galeria</a></li>
    <li><a href="<?php URL?>comentarios" class="ler"><i class="fa fa-font"></i> Comentarios</a></li>
    <li><a href="<?php URL?>informacoes" class="ler"><i class="fa fa-font"></i> Informacoes</a></li>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-caret-square-o-down"></i> Menu <b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li><a href="#">Enviar Email</a></li>
            <li><a href="#">Gerir Usuarios</a></li>
        </ul>
    </li>
</ul>

And the%% of% where pages will be loaded:

<!-- /#navegacao -->
<div id="open"></div>
<!-- /#navegacao //Fim -->
    
asked by anonymous 04.06.2014 / 16:58

2 answers

0

You are most likely experiencing the problem you described because you invoked an event method through a response argument, which is always a string.

See working in Fiddle

The event argument must be defined in an event handler. In your case, a click event, so it is an argument from the first callback .

The second callback is the server response, which is a string (test with typeof ), so the event.preventDefault () does not exist.

Incidentally, when using jQuery.load (), informing a callback is almost always useful only during development, just to have access to the XHR object and suddenly extract the HTTP Response Code (200, 301, 404 ...) and its meaning (OK, Moved, Not Found ...).

    
04.06.2014 / 19:40
0

After reading and searching here in the forum, I found a solution

function abreURL (url, method, where) {    if (method == 'POST') {       // method post        $ .post (url, function (data) {       // loader page (loading)        $ ("#loader") show ();        $ ("#" + where) .load (url);       });    }    else if (method == 'GET') {       // method get       $ .get (url, function (data) {      // loader page (loading)       $ ("#loader") show ();      $ ("#" + where) .load (url);     });   } }

E In the html and just call the function onclick () method

views / category / index.php ',' GET ',' content '); "href=" # ">

    
05.06.2014 / 18:04