Problem with my Javascript Code
Could anyone tell me why this code doesn't work? I can't even get the alert(); in init() to work right...
window.onload = init;
var downloadedstuff;
function init() {
alert();
$.get('example.php'开发者_如何学Go + '?v=' + Math.random(), success: function (data) {
downloadedstuff = data;
});
doTimer();
}
var t;
var timer_is_on=0;
function timedCount()
{
$.get('example.php' + '?v=' + Math.random(), success: function (data) {
if(data != downloadedstuff)
{
alert('SOMETHING HAPPENED!!!!');
location.reload(true);
}
else
{
alert(data);
}
});
t=setTimeout("timedCount()",5000);
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
once again, really sorry for all the questions, i just don't know what's wrong.
This line (which occurs twice):
$.get('example.php' + '?v=' + Math.random(), success: function(data) {
should be:
$.get('example.php' + '?v=' + Math.random(), function(data) {
since the :
is for javascript objects
精彩评论