使用JAVASCRIPT几乎以不可见的方式重新加载内容,并且没有闪烁效果

使用JAVASCRIPT几乎以不可见的方式重新加载内容,并且没有闪烁效果,javascript,jquery,html,Javascript,Jquery,Html,我正在编写一个小程序,其中我使用$获取数据。get然后显示到目前为止的数据,很好,然后有这个部分,然后当我单击某个链接时,它刷新页面,但它有这种闪烁效果。是否有办法重新加载内容获取新的更新内容,然后替换以前加载的数据 注意:我没有使用setInterval或setTimeout函数,因为它会减慢我网站的进程。任何不包括这些功能的答案都非常感谢 这是密码 function EmployeeIssues(){ $('#initial_left').css({'display' : 'none'});

我正在编写一个小程序,其中我使用$获取数据。get然后显示到目前为止的数据,很好,然后有这个部分,然后当我单击某个链接时,它刷新页面,但它有这种闪烁效果。是否有办法重新加载内容获取新的更新内容,然后替换以前加载的数据

注意:我没有使用setInterval或setTimeout函数,因为它会减慢我网站的进程。任何不包括这些功能的答案都非常感谢

这是密码

function EmployeeIssues(){
$('#initial_left').css({'display' : 'none'});
var table = $('#table_er');

$.get('admin/emp_with_issues', function(result){
    var record = $.parseJSON(result);
    var data = record.data,
        employees = data.employees,
        pages = data.pages;
    if(employees){

        $('#er_tab_label').html('<b>Employees with Issues</b>');
        for (var i = 0; i < employees.length; i++) {
            $('#table_er').fadeIn('slow');
            table.append(write_link(employees[i]));  // function that displays the data
        }
        if(pages){
            $('#pagination').html(pages);
        }
    }else{
        $('#er_tab_label').html('<b>No employees with issues yet.</b>');
    }
});
table.html('');
}
我应该如何显示内容而不产生任何闪烁效果?
谢谢:-)

此部分可能是问题所在:

if(employees){
    $('#er_tab_label').html('<b>Employees with Issues</b>');
    for (var i = 0; i < employees.length; i++) {
        $('#table_er').fadeIn('slow');
        table.append(write_link(employees[i]));  // function that displays the data
    }
    if(pages){
        $('#pagination').html(pages);
    }
} else ... 
if(员工){
$('er#u tab_label').html(“有问题的员工”);
对于(变量i=0;i
似乎您要求table_er在每次循环运行时淡入一次,而如果只有一个这样的表,您只需要淡入一次

首先,试着像这样重新播放:

if(employees){
   $('#er_tab_label').html('<b>Employees with Issues</b>');
   $('#table_er').hide(); // hide it while we add the html
   for (var i = 0; i < employees.length; i++) {
       table.append(write_link(employees[i]));  // function that displays the data
   }
   $('#table_er').fadeIn('slow'); // only do this after the table has all its html

   if(pages){
       $('#pagination').html(pages);
   }
} else ....
if(员工){
$('er#u tab_label').html(“有问题的员工”);
$('#table_er').hide();//在添加html时隐藏它
对于(变量i=0;i
另一种可能性是,您正在运行一个循环,并要求jquery在循环运行时执行一些操作。最好是以字符串形式计算出新页面数据的整个HTML,然后让屏幕在一行中呈现它。我不为你做这件事,因为我不知道write\u link等中有什么内容,但类似的东西

if(employees){
   $('#er_tab_label').html('<b>Employees with Issues</b>');
   var sHTML ="";
   $('#table_er').hide(); // hide it while we add the html
   for (var i = 0; i < employees.length; i++) {
      sHTML+=write_link(employees[i]); // maybe this is right ? if write_link returns an HTML string ?
   }

   table.append(sHTML);  // add the HTML from the string in one go - stops the page rendering while the code is running

   $('#table_er').fadeIn('slow'); // now show the table.

   if(pages){
       $('#pagination').html(pages);
   }
} else ...
if(员工){
$('er#u tab_label').html(“有问题的员工”);
var sHTML=“”;
$('#table_er').hide();//在添加html时隐藏它
对于(变量i=0;i
调用员工问题的按钮function@jily_101您有JSFIDLE中的示例吗?抱歉,我没有。我唯一的问题是,当它打开时,表格会闪烁reloads@jily_101您是否尝试过,首先是table.hide(),然后是数据可用时的table.show()
if(employees){
   $('#er_tab_label').html('<b>Employees with Issues</b>');
   var sHTML ="";
   $('#table_er').hide(); // hide it while we add the html
   for (var i = 0; i < employees.length; i++) {
      sHTML+=write_link(employees[i]); // maybe this is right ? if write_link returns an HTML string ?
   }

   table.append(sHTML);  // add the HTML from the string in one go - stops the page rendering while the code is running

   $('#table_er').fadeIn('slow'); // now show the table.

   if(pages){
       $('#pagination').html(pages);
   }
} else ...