So I have a page that uses some JQuery to reload a php file every 15 seconds, nothing special. The php file simply echos that last 3 lines of a textfile.
Here's the JQuery:
$(document).ready(function() {
$("#realtime").load("realtime.php");
var refreshId = setInterval(function() {
$("#realtime").load('realtime.php');
}, 15000);
$.ajaxSetup({ cache: false });
});
And lets just say for a clear example the PHP file is:
echo "<li class='alternate'>query 1</li>";
echo "<li class='alternate'>query 2</li>";
echo "<li class='alternate'>query 3</li>";
I would like to achieve 2 things, firstly I would only like the PHP file to update when a form has been submitted in real time so it's not just updating every 15 seconds, I am guessing this will involve some kind of cache storage or something?
Secondly you may have noticed the li class is named alternate because the colors alternate how would I be able to change this from odd to even when the form has recently been submitted also. Jquery so far is:
$(document).ready(function(){
$('#myList li:nth-child(odd)').addClass('alternate');
});
I have most of the pieces but placing them together is puzzling me although it may seem very simple, can anyone help? Thanks.