简体   繁体   English

动态刷新div内容

[英]refresh div contents dynamically

Hello I am having trouble regarding div reloading when a new record has been added. 您好,我在添加新记录时无法重新加载div。 What I wanted to do is to show first a loading image then after a record has been inserted it will reload the 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;
});

That's what I got to far when I'm trying the code it refreshes a whole physical of page on the div & not the desired div itself. 这就是我尝试代码时可以达到的效果,它刷新了div上整个页面的物理内容,而不是所需的div本身。 . .

Sorry guys I am poor with jQuery and BTW this is in CodeIgniter. 抱歉,我对jQuery和BTW不满意,这是在CodeIgniter中。

Your problem is, that codeigniter obviously returns a whole html page. 您的问题是,codeigniter显然会返回整个html页面。 You have two choices: 您有两种选择:
Either return only a fragment (I don't know how to do this in CI) or use jQuery to parse out the div you want. 要么只返回一个片段(我不知道如何在CI中执行此操作),要么使用jQuery解析出所需的div。 This can be done with the following code, assuming that the div you want is named <div id="results_div">...</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吗?

This is my best guess without html to work with: 这是我最好的猜测,没有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM