[英]refresh div contents dynamically
您好,我在添加新記錄時無法重新加載div。 我想做的是先顯示一個加載圖像,然后在插入記錄后將重新加載div。
$("a.follow").click(function(event) {
event.preventDefault();
$("#flash").show();
$("#flash").fadeIn(300).html('<img src="ajax-loader-transp.gif" />Loading Result.');
$.ajax({
//url: $(this).attr("href"),
success: function(msg) {
$("#results_div").load('http://localhost/<app_name>/index.php/<contoller>/index');
}
});
return false;
});
這就是我嘗試代碼時可以達到的效果,它刷新了div上整個頁面的物理內容,而不是所需的div本身。 。 。
抱歉,我對jQuery和BTW不滿意,這是在CodeIgniter中。
您的問題是,codeigniter顯然會返回整個html頁面。 您有兩種選擇:
要么只返回一個片段(我不知道如何在CI中執行此操作),要么使用jQuery解析出所需的div。 可以使用以下代碼完成此操作,假設您想要的div被命名為<div id="results_div">...</div>
$("a.follow").click(function(event) {
event.preventDefault();
$("#flash").show();
$("#flash").fadeIn(300).html('<img src="ajax-loader-transp.gif" />Loading Result.');
$("#results_div").load('http://localhost/<app_name>/index.php/<contoller>/index #results_div', function(){ $('#flash').hide(); });
});
您可以在#results_div div中包含HTML嗎?
這是我最好的猜測,沒有html可以使用:
$("a.follow").click(function(event) {
event.preventDefault();
// show the linke
$("#flash").fadeIn(300).html('Loading Result.');
//ajax load the 'mini div' result -- i guessed that this url pulls back the div you want
$("#results_div").load('http://localhost/<app_name>/index.php/<contoller>/index', function(data, text, xhr){
$('#flash').fadeOut("fast");
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.