谁能告诉我为什么这段代码不起作用?我什至无法得到alert();在 init() 中正常工作...
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(), success: function(data) {
应该是:
$.get('example.php' + '?v=' + Math.random(), function(data) {
因为 :
用于 javascript 对象
关于javascript - 我的 Javascript 代码有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7368680/