使用javascript自动刷新div

情况我试图自动刷新Joomla 2.5中文章中定义的标签

   var auto_refresh = setInterval( function() { alert("testing"); $('#results').fadeOut('slow').load('#results').fadeIn("slow"); }, 20000);  
{szakitable csv = "http://127.0.0.1/msedcl/Archives/status2.csv" csvseparator="," width= 430} {/szakitable}

上面的代码使用了一个名为szaki tables的扩展,它允许将csv文件直接嵌入到文章中。 我要求div应该每20秒重新加载一次,以便csv文件中的更改反映在网页上。 问题当我调用“$(’#results’)。fadeOut(’slow’)。load(’#results’)。fadeIn(”slow“);” 会发生什么是在div区域内重新加载整个页面。 这不是我要求的。

有任何建议请!

你试过这个吗?

 $('#results').fadeOut('slow').load('{current_page.html} #results').fadeIn("slow"); 

将{current_page.html}替换为文档的文件名

使用回调的另一种方式

 $('#results').fadeOut('slow', function(){ $(this).load('index.html #results').fadeIn("slow") }); 

请参阅.load()以将外部数据从其他页面加载到当前页面而不刷新整个页面。

当我看到你的代码时,你正在加载div #results ,它根本不起作用。

来自DOCS:

Loading Page Fragments:

.load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted..load() method, unlike $.get(), allows us to specify a portion of the remote document to be inserted. 这是通过url参数的特殊语法实现的。 如果字符串中包含一个或多个空格字符,则假定第一个空格后面的字符串部分是确定要加载的内容的jQuery选择器。

example:

 $('#result').load('ajax/test.html #container'); 

这将加载这是gets the test.htmlfind the element with id of container并将其加载到当前页面上的元素result


所以在你的情况下:

 var auto_refresh = setInterval(function(){ alert("testing"); $('#results').fadeOut('slow').load('targetpage.php #results').fadeIn("slow"); }, 20000); //-------------------------^^^^^^^^^^^^^^---required 

或者如果您以其他方式加载它,那么您可以这样做:

 $('#results').fadeOut('slow').fadeIn("slow");