2013-03-19 64 views
1

我在控制器中得到了下面的方法(ProductController的,例如)。Rails的:當雙鏈接上點擊,兩個彈出式窗口打開

def show 
    respond_with do |format| 
     format.html do 
     if request.xhr? 
      @product = ... 
      render :status => 200, :partial => 'products/show' 
     end 
     end 
    end 
    end 

當用戶點擊產品鏈接時,彈出窗口將打開產品圖片和說明。

問題:當產品鏈接給定用戶雙擊,雙彈出窗口打開。調試時,我注意到,ProductController#show方法被調用一次,但仍然是兩個彈出窗口被打開。

回答

1

可能是你通過AJAX發送請求到服務器?第二個請求將是您鏈接的默認行爲。試試這個

$("a.your_link").click(function(e){ 
    e.preventDefault(); // this will consume default functionality of your link 
    //now send request to server 
    $.ajax(url: your_url).done(function(output){ 
    alert(data); 
    }); 
}); 
相關問題