Monday, October 6, 2014

Auto refresh div with external php or html file in jquery

This tutorial will help you auto refresh a div using jquery load() function. We will change the #theDiv to the external php or html files content every 5 seconds
 Html sample
        
The content of this div will refresh
Jquery Code
 take not that we first load the sample.php so that it will run immediately after our page loads. then after 5 seconds. the set interval will run and run every 5 seconds
        //load first the sample.php  
	$( "#theDiv" ).load( "../external/sample.php" );

	//after 5 seconds run this code
	setInterval(function () {
		$( "#imgdiv" ).load( "../external/sample.php" );
	}, 5000);

No comments:

Post a Comment