Reputation: 97
Is there is a way, using jquery maybe, to auto refresh a particular div but NOT load it from another page?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#auto').load('process.php').fadeIn("slow");
}, 10000);
</script>
</head>
<body>
<div id="auto">
</div>
Currently it loads process.php into the div "auto". Is it possible to have some php code in that div which runs at the set interval time ON THE SAME PAGE, without having to load an external page?
Upvotes: 0
Views: 2860
Reputation: 1617
No, there is no possible way to auto-refresh div without using external file...but you don't want external file include....then you have to use... ".html"...instand of ".load"...and get all html data from another file and replace fresh data.
Upvotes: 2
Reputation: 4081
You must take into consideration how the web works. You need to make a REQUEST before the web server can build/send a RESPONSE. Therefore, if you don't have AJAX interaction, you can't make a request, and therefore will never receive a response. If all of your data is known ahead of time, you can put it all on the original page (RESPONSE) then hide/show the appropriate divs, but it sounds to me like you want live data, in which case you need to REQUEST the live data from the server.
Upvotes: 0
Reputation: 20193
No. You need to issue AJAX request every time in order to refresh content of the element. (as you described using setInterval()
)
Upvotes: 1
Reputation: 17390
No. PHP is run on the server, buy the time it gets to the browser, the PHP code is gone and it is only HTML/CSS/JS etc.
What you are using it the proper way to do it.
Upvotes: 1