我有一個問題在頁面加載時的javascript腳本只裝載一次,但我需要它每次我從的WebMethod獲得服務器端如何在每次使用ajax從WebMethod加載數據時運行腳本?
這裏的數據的時間是我的代碼:
我JavaSript AJAX:
<script type="text/javascript">
$(document).ready(function() {
function InfiniteScroll() {
$('#divPostsLoader').html('<img src="img/loader.gif">');
$.ajax({
type: "POST",
url: "Home.aspx/GetLastArticles",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data != "") {
$('#divPostsLoader:last').after(data.d);
}
$('#divPostsLoader').empty();
},
error: function (data) {
if (!document.getElementById('#divPostsLoader').innerHTML == "<p>END OF POSTS</p>")
$('#divPostsLoader').empty();
$('#divPostsLoader').html("<p>END OF POSTS</p>");
}
})
};
var b = false;
//When scroll down, the scroller is at the bottom with the function below and fire the lastPostFunc function
$(window).scroll(function() {
if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
InfiniteScroll();
}
b = true;
});
if (!b) {
window.onload = function() {
InfiniteScroll();
};
}
});
</script>
,這裏是我的javasript,我希望它火每次我從GetLastArticles
的WebMethod獲取數據:
<script type="text/javascript">
$(".tag_button").on('click', function (e) {
e.preventDefault(); // prevent default action - hash doesn't appear in url
$(this).parent().find('div').toggleClass('tags-active');
$(this).parent().toggleClass('child');
});
</script>
我的aspx頁面(客戶端):
<div class="tags_list">
<a class="tag-icon tag_button" href="#" >Tags</a>
<div class="tags">
<a class="tag-icon" href="#" >Tag1</a>
<a class="tag-icon" href="#">Tag2</a>
<a class="tag-icon" href="#">Tag3</a>
<a class="tag-icon" href="#">Tag4</a>
<a class="tag-icon" href="#">Tag5</a>
<a class="tag-icon" href="#">Tag6</a>
<a class="tag-icon" href="#">Tag7</a>
</div>
</div>
謝謝,真的很幫我 –
很高興知道。你太客氣了。 –