php - 动态刷新div内容

标签 php jquery mysql codeigniter

您好,我在添加新记录后重新加载 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/

相关文章:

php - 我如何将 HTML 格式化为类似于 MS Word 的两列格式?

java - 将字符串数组作为 POST 传递给 PHP

JavaScript 的 lastIndexOf()

php - 使用最近上传的图像来更新 PHP 中的数据库

java - Spring JPA - MySQL 数据库创建外键时 Hibernate 出错

php - 从 cURL 检索文件的最后一行

php - 在 PHP echo 中运行 PHP?

javascript - JavaScript 中是否有将值转换为数字格式的函数?

jquery - 动态替换对话框按钮文本

mysql - Zend 的多个子查询