jQuery GET将代码注入div并刷新(jQuery GET inject code into div and refresh)

我使用jQuery GET从本地文件获取源代码并将代码注入div 。

我的问题是,这个代码不刷新。

jQuery的

jQuery.get("some_local_file_url_here", function( the_page_source ) { jQuery("#target_div").html(the_page_source); });

HTML

<div id="target_div"> the_page_source goes here </div>

我怎样才能让它工作,因为我重新加载到页面?

I am getting the source code from a local file using jQuery GET and injecting the code into a div.

My problem is that this code is not refreshing.

jQuery

jQuery.get("some_local_file_url_here", function( the_page_source ) { jQuery("#target_div").html(the_page_source); });

HTML

<div id="target_div"> the_page_source goes here </div>

How can I get it to work as it I did a reload to the page?

最满意答案

window.setInterval(function(){ jQuery.get("some_local_file_url_here", function( the_page_source ) { jQuery("#target_div").html(the_page_source); }); }, 3000);

setInterval()方法以指定的时间间隔(以毫秒为单位)调用函数或计算表达式。

提示:

3000 =每3秒

1000 = 1秒

你可以改变它。

阅读更多: Window setInterval()方法

window.setInterval(function(){ jQuery.get("some_local_file_url_here", function( the_page_source ) { jQuery("#target_div").html(the_page_source); }); }, 3000);

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).

TIPS:

3000 = every 3 seconds

1000 = 1 second

You can change it.

read more: Window setInterval() Method

更多推荐