我的Javascript代码有问题
有人能告诉我为什么这个代码不起作用吗?我甚至不能得到警报();要在init()中正常工作我的Javascript代码有问题,javascript,Javascript,有人能告诉我为什么这个代码不起作用吗?我甚至不能得到警报();要在init()中正常工作 window.onload = init; var downloadedstuff; function init() { alert(); $.get('example.php' + '?v=' + Math.random(), success: function (data) { downloadedstuff = data; }); doTimer(); } var t; va
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();
}
}
再一次,对于所有的问题,我真的很抱歉,我只是不知道出了什么问题。这一行(出现两次):
应该是:
$.get('example.php' + '?v=' + Math.random(), function(data) {
由于:
用于javascript对象,因此此行(出现两次):
应该是:
$.get('example.php' + '?v=' + Math.random(), function(data) {
因为
:
是针对javascript对象的,所以alert()会生成一个错误,因为alert需要一个字符串作为参数。至少在IE9中不会,但我会添加一个字符串以防万一:p你知道,alert()会生成一个错误,因为alert需要一个字符串作为参数。至少在IE9中不会,但我会添加一个字符串以防万一:p