您好,我在添加新记录后重新加载 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,顺便说一句,这是在 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(); });
});
关于php - 动态刷新div内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7906195/