0

두 개의 드롭 다운 목록에 하나의 ID가 있고 다른 하나는 드롭 다운 목록을 표시하는 액션과 아약스 요청을 트리거하고 싶습니다. 그리고 어떻게 이런 일을 시도하고 있지만 약간의 오해가 있습니다.이 경우에는 아약스 요청이 발생했지만 드롭 다운 목록에 두 개의 드롭 다운 목록이 모두 표시됩니다.Twitter 부트 스트랩 드롭 다운 오작동

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

답변

0

이 작업을 수행하는 우아한 방법이있을 최대량 : 다른 경우

  <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) { 

    }); 

    }); 

나는 Bootstrap Docs에서 설명하는 대신 데이터 대상 속성을 사용하여 같은 HREF하려고하지만 브라우저에 오류가 하지만 여기에 문제를 해결할 수있는 해결 방법이 있습니다.

$("#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) { 

    }); 

    }); 
관련 문제