Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的Javascript代码有问题_Javascript - Fatal编程技术网

我的Javascript代码有问题

我的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

有人能告诉我为什么这个代码不起作用吗?我甚至不能得到警报();要在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(), function(data) {
由于
用于javascript对象,因此此行(出现两次):

应该是:

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

因为
是针对javascript对象的,所以alert()会生成一个错误,因为alert需要一个字符串作为参数。至少在IE9中不会,但我会添加一个字符串以防万一:p你知道,alert()会生成一个错误,因为alert需要一个字符串作为参数。至少在IE9中不会,但我会添加一个字符串以防万一:p