0

I'm getting "Uncaught ReferenceError: refreshAgonas is not defined "

The players div is filled correctly. Do I need some kind of special define with the JS functions in the JS file?

<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;
    });
}
4
  • 1
    Are you sure the path to the JS file is correct? Try adding "../" or other elements that would help the browser located the file. Commented Jan 3, 2014 at 12:08
  • Both functions are in the jquery-draw.js file. Why would refreshPlayers work and refreshAgonas not? Maybe i'm supposed to declare them with some other way? i dk Commented Jan 3, 2014 at 12:09
  • Are you sure the players one is loading? Do you see the console.log("success") ? Commented Jan 3, 2014 at 12:10
  • yes here you go i43.tinypic.com/14lpzzc.png Commented Jan 3, 2014 at 12:11

3 Answers 3

1

Now I saw the problem:

Replace

var inRequesG = false;

With

var inRequestG = false;

You forgot the "t"

Sign up to request clarification or add additional context in comments.

2 Comments

This is indeed a problem but I don't think it would cause the uncaught reference error
Indeed it doesn't make sense although i had it corrected before you mentioned it. But for some reason it runs smoothly now.
1

Try defining the functions like this:

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

Try this and respond with the results.

EDIT: didn't mean to include the parenthesis.

4 Comments

Yeap figured that out, still nothing though. Players div is filled fine, agonas nothing
How about putting the code you need in the document load event?
Not familiar with the method, let me look it up and give it a try
In a header script tag add: $( function () { //doStuff } ); You can find more here: api.jquery.com/ready
0

Try replacing:

setInterval( refreshAgonas, 5000);

With this:

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

2 Comments

only difference now is that is shows the Ref Error again and again in the console
This could work if refreshAgonas would be defined later, but I don't think that's the case. Evenso you should resolve the define issue and not add silly workarounds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.