ReferenceError js函数未定义

时间:2014-01-03 12:05:15

标签: javascript

我收到“Uncaught ReferenceError:refreshAgonas未定义”

玩家div正确填充。我是否需要在JS文件中使用JS函数进行某种特殊定义?

<html>    
  <head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
  </head>
  <script type="text/javascript" src="jquery.js"></script>
  <script type="text/javascript" src="jquery-draw.js"></script>
  <h2>Game</h2> 
  <div class="agonas">
    <script>
        setInterval(refreshAgonas, 5000);
        var inRequesG = false;
    </script>
  </div>
  <h2>Players</h2>
  <div class="players">
    <script>
      setInterval(refreshPlayers, 5000);
      var inRequest = false;
    </script>
  </div>

</html>

的jquery-draw.js

   function refreshPlayers() {
    if (inRequest) {
        return false;
    }
    inRequest = true;
    var load = $.get('playersdata.php');
    $(".players").html('Refreshing');
    load.error(function () {
        console.log("Mlkia kaneis");
        $(".players").html('failed to load');
        // do something here if request failed
    });
    load.success(function (res) {
        console.log("Success");
        $(".players").html('<table border="1"><tr><th>ID</th><th>Name</th><th>Email</th><th>League</th><th>Sex</th><th>Birthday</th></tr>' + res + '</table>');
    });
    load.done(function () {
        console.log("Completed");
        inRequest = false;
    });
}

function refreshAgonas() {
    if (inRequestG) {
        return false;
    }
    inRequestG = true;
    var load = $.get('playersdata.php');
    $(".agonas").html('Refreshing');
    load.error(function () {
        console.log("Mlkia kaneis");
        $(".agonas").html('failed to load');
        // do something here if request failed
    });
    load.success(function (res) {
        console.log("Success");
        $(".agonas").html('<table border="1"><tr><th>ID</th><th>Name</th><th>Email</th><th>League</th><th>Sex</th><th>Birthday</th></tr>' + res + '</table>');
    });
    load.done(function () {
        console.log("Completed");
        inRequestG = false;
    });
}

3 个答案:

答案 0 :(得分:1)

尝试定义这样的函数:

var refreshPlayers = function () {};
var refreshAgonas = function () {};

尝试此操作并回复结果。

编辑:并不意味着包含括号。

答案 1 :(得分:1)

现在我看到了问题:

替换

var inRequesG = false;

使用

var inRequestG = false;

你忘记了“t”

答案 2 :(得分:0)

尝试更换:

setInterval( refreshAgonas, 5000);

有了这个:

setInterval(function(){ refreshAgonas()}, 5000);