I'm currently using below method to call an external php file with some variables using javascript
<script src="http://www.domain.com/function.php?param=A" type="text/javascript"></script>
And the code in the function.php file will return data in Javascript format, something like
<?php Header("content-type: application/x-javascript");
$p = $_GET['param'];
$r = mt_rand(0, 10);
echo "document.write('" . $p . $r . "');";
?>
This is just a simple example. My problem is on Google Chrome (v19), if the page had not finished loaded, the random number will not be random when I keep refreshing. It will become truly random only when I hit the refresh button AFTER the page finished load. Why is this happen and how can I solve it?
I tested on Firefox 12 and IE8, even if I refresh the page before it finished load, the random number will always be regenerated.
Math.random()?