Dropdown Twitter Bootstrap, being ignored in the Ajax request

1

Hello, Stack Over Flow community, I am trying to include pages via ajax , but when I click to open dropdown it is ignored and adds the page Index of WampServer how to proceed in these cases?

Here I will put an image and the code JavaScript :

$(function() {
    $("#loading").hide();

    $("ul.nav a").click(function() {
        page = "template/pages/"+$(this).attr('href')

        $("#loading").ajaxStart(function() {
            $(this).show();
        });

        $("#loading").ajaxStop(function() {
            $(this).hide();
        });

        $("#main").load(page)
        return false;
    });
});

Main: Content:

<section id="main" class="section-main">
    <img src="template/assets/images/icons/load.gif" id="loading">
    <?php
    include("./template/pages/meus-tickets.php");
    ?>
</section>

Menu:

<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
    <i class="glyphicon glyphicon-user"></i> <span class="caret"></span>
  </a>
  <ul class="dropdown-menu">
    <li><a href="#"><i class="glyphicon glyphicon-edit"></i> Editar perfil</a></li>
    <li><a href="novo-ticket.php"><i class="glyphicon glyphicon-open"></i> Submeter um ticket</a></li>
    <li role="separator" class="divider"></li>
    <li><a href="#"><i class="glyphicon glyphicon-log-out"></i> Sair</a></li>
  </ul>
</li>
</ul>

Note: I would like links without dropdown and dropdown to continue working, waiting for answers. [] 's

    
asked by anonymous 13.02.2016 / 13:07

1 answer

1

If I understand the goal, you can ignore those elements whose destination URL is equal to # :

$(function() {
    $("#loading").hide();

    $("ul.dropdown-menu a").click(function() {

        // ignora href="#"            
        if ($(this).attr('href') == "#") return false; 

        page = "template/pages/"+$(this).attr('href')

        $("#loading").ajaxStart(function() {
            $(this).show();
        });

        $("#loading").ajaxStop(function() {
            $(this).hide();
        });

        $("#main").load(page)
        return false;
    });
});
    
13.02.2016 / 13:32