I have no experience of Ajax and little experience of java, lots of sql & php experience so I will probably receive lots of comments for this question but here goes.
Ultimately I have 4 flash swf files that needs to be rotated on the website main page randomly. So I've found a shuffle javascript function online and implemented that. Now I need to implement this ajax function (from this post Javascript change inner html of div that conatins php include ) to change the swf files according to the numbers in the array, so if tempArray = 4,3,1,2 then display flash-4.php for 3sec, then change to flash-3.php for 3sec, then change to flash-1.php for 3sec, etc.
I've got the shuffle part working:
<script type="text/javascript">
Array.prototype.shuffle = function() {
var input = this;
for (var i = input.length-1; i >=0; i--) {
var randomIndex = Math.floor(Math.random()*(i+1));
var itemAtIndex = input[randomIndex];
input[randomIndex] = input[i];
input[i] = itemAtIndex;
}
return input;
}
var tempArray = [ 1, 2, 3, 4 ]
tempArray.shuffle();
// and the result is...
alert(tempArray);
//alert(tempArray[0]);
</script>
I've got the ajax part where it's replacing the content working:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
setInterval(function()
{
$.ajax( "flash-2.php" )
.done(function(res) {
document.getElementById("swfdiv").innerHTML = res;
})
},
3000);
</script>
But how do I put it together to rotate depending on the array values?