0

I have two dropdown one have an id and the other have not, and I want to trigger an ajax request and the action to show the dropdown list. And this is how Im trying to do it, but has some misbehavior, in this case the ajax request it's triggered but when shows the dropdown list it shows both dropdown list.

          <li class="dropdown top-dropdown">
            <a href="#" class="dropdown-toggle" style="padding-right:0;" data-toggle="dropdown">hola</a>
            <ul class="dropdown-menu">
              <li>
                <a href="/hola"><i class="icon-user"></i>
                  Profile
                </a>
              </li>
              <li>
                <a href="/hola"><i class="icon-wrench"></i>
                  Settings
                </a>
              </li>              
            </ul>
          </li>

          <li id="hola" class="dropdown">
            <a id="go_do_something" href="<%= url %>" class="dropdown-toggle disabled" style="padding-right:0;" data-toggle="dropdown">           
              <b id="noti_container">
                <i class="icon-bullhorn"></i>
              </b>
            </a>
            <ul class="dropdown-menu">              
                <li>
                  <a href="/hola">
                    <i>added on yesterday</i>
                  </a>
                </li>              
              <li class="divider"></li>
              <li>
                <a href="#">
                  See All
                </a>
              </li>
            </ul>  
          </li>

$("#go_do_something").live("click", function(){      
    var update_user_last_n = $(this).attr('href');

    $.ajax({
      type: 'GET',
      url: update_user_last_n
    }).done(function(xhr, status) {            
      $("#hola").dropdown('toggle');
    }).fail(function(xhr, status) {

    });  

  });

In other case I try to use the data-target attribute instead href like describe in Bootstrap Docs but I get an error on the browser:

Uncaught Error: Syntax error, unrecognized expression: {url_on_data-target}
4

1 回答 1

0

最有一种优雅的方法可以做到这一点,但这里有一个解决问题的解决方法:

  $("#go_do_something").live("click", function(event){
    event.preventDefault();  
    var this_a = this;  
    var url = $(this_a).attr('href');

    $.ajax({
      type: 'GET',
      url: url
    }).done(function(xhr, status) {                  
      $(this_a).removeClass("disabled");
      $(this_a).click();
    }).fail(function(xhr, status) {

    });  

  });
于 2012-12-20T17:00:45.667 回答