2011-09-10 26 views
0

有谁能告诉我为什么这段代码不起作用吗?我什至不能得到警报();在init()工作正确...问题与我的Javascript代码

window.onload = init; 

var downloadedstuff; 

function init() { 
alert(); 
    $.get('example.php' + '?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(); 
    } 
} 

再次,真的很抱歉的所有问题,我只是不知道什么是错的。

+0

你知道,警报()会产生一个错误警报需要一个字符串作为参数。 – Eineki

+0

至少不在IE9中,但我会添加一个字符串以防万一:P – MatthewSot

回答

4

这行(这发生两次):

$.get('example.php' + '?v=' + Math.random(), success: function(data) { 

应该是:

$.get('example.php' + '?v=' + Math.random(), function(data) { 

因为:是对JavaScript对象

+0

哦哇......谢谢! – MatthewSot