2012-06-01 166 views
0
<li> 
    <div class="slidera_img"> 
    <a href="image.jpg" rel="example_group" title="<a href='#' onClick='ajaxpost(@item.Id)'><img src='foo.jpg'/></a>"> 
    <img src="@Url.Action("ViewImage", "Image", new { id = item.Id, imageType = "thumb" })" alt="" width="100" height="100" /> 
    </a> 
    </div> 
    <div class="slidera_num">@item.VoteCount</div> 
</li> 

我有上面的代碼打開一個模式框,在slidera_img div裏面的href使得ajax得到下面的代碼。之後,我希望能夠將slidera_num類的div更新爲我從ajax請求獲得的當前值。ajax調用後更新div

<script type="text/javascript"> 
    function ajaxpost(id) { 
     var item = $(this).parent(); 
     alert(item); 
     $.get('@Url.Action("VoteAjax","Home")', { id: id }, function (response) { 
      item.closest("li").find(".slidera_num").html(response.vote); 
     }); 
    } 

我之上,但沒有運氣嘗試。

我該怎麼做?

謝謝。

+0

爲什麼你的href標籤是在你的title屬性中? –

+0

這是多麼fancybox的作品 – DarthVader

回答

1

第一隻鏈接,你需要:

<a href="image.jpg" rel="example_group"><img src="@Url.Action("ViewImage", "Image", new { id = item.Id, imageType = "thumb" })" alt="" width="100" height="100" /></a> 

然後調用的fancybox來顯示它。在該呼叫中,您可以使用onComplete事件掛鉤,該事件返回該項目,然後調用您需要更新頁面的任何其他ajax呼叫。 so just called it:

$("img[rel='example_group'").fancybox({ onComplete: function(item){ 
    $.get('@Url.Action("VoteAjax","Home")', { id: item.id }, function (response) { 
     $(item).closest("li").find(".slidera_num").html(response.vote); 
    }); 
}}); 
0

不知道的fancybox是怎麼工作的,我不能幫你多少,但我可以建議一些事情:

  1. 檢查你的瀏覽器,如果有一個JavaScript錯誤。如果任一 ajaxpost()或ajax回調函數失敗,您的代碼將不會 工作。
  2. 使用調試器在瀏覽器中打開您的頁面,例如使用Web Inspector的Webkit瀏覽器或使用Firebug的Firefor,並在您的ajaxpost()和ajax回調中各放一個斷點。檢查您是否選擇了正確的元素。物品是你期望的嗎?您的ajax回調中的選擇器鏈是否找到您期望找到的內容?
  3. 告訴原始的ajaxpost()是什麼樣的,以及你添加了什麼。同時告訴我們當你的fancybox被加載時你的html轉換成什麼。你也可以在Web Inspector或Firebug中看到。有了這些信息,有人可能會提供幫助。到圖像