Dropdown Twitter Bootstrap, ignored in Ajax request

Asked

Viewed 65 times

1

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

Here I 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>

inserir a descrição da imagem aqui

Note: I would like the links without dropdown and with dropdown were still functioning, I await answers. []’s

  • Add HTML as well, please

  • Added to main topic.

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;
    });
});
  • Thank you very much, but that’s not what I want :/, I want ajax to include the links without dropdown and with dropdown, because the way I’m doing is catching the dropdown

  • You want to only run the function when the links inside dropdown-menu are clicked? It can be more specific because it is not clear what you call 'link without dropdown' and 'link with dropdown'

  • I want all links to work if I change $("ul.nav a").click(function() { for $("ul.nav ul a").click(function() { the code stops working...

  • Change to ul.dropdown-menu a, as I did in the code...

  • worked thanks

  • Problem-free :)

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.