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;
});
}
Deepak Ingole
15.9k10 gold badges49 silver badges80 bronze badges
asked Jan 3, 2014 at 12:05
LefterisL
1,1534 gold badges18 silver badges37 bronze badges
-
1Are you sure the path to the JS file is correct? Try adding "../" or other elements that would help the browser located the file.aaron-bond– aaron-bond2014年01月03日 12:08:24 +00:00Commented 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 dkLefterisL– LefterisL2014年01月03日 12:09:40 +00:00Commented Jan 3, 2014 at 12:09
-
Are you sure the players one is loading? Do you see the console.log("success") ?aaron-bond– aaron-bond2014年01月03日 12:10:22 +00:00Commented Jan 3, 2014 at 12:10
-
yes here you go i43.tinypic.com/14lpzzc.pngLefterisL– LefterisL2014年01月03日 12:11:35 +00:00Commented Jan 3, 2014 at 12:11
3 Answers 3
Now I saw the problem:
Replace
var inRequesG = false;
With
var inRequestG = false;
You forgot the "t"
answered Jan 3, 2014 at 12:26
cretzzzu3000
2211 silver badge7 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
aaron-bond
This is indeed a problem but I don't think it would cause the uncaught reference error
LefterisL
Indeed it doesn't make sense although i had it corrected before you mentioned it. But for some reason it runs smoothly now.
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.
answered Jan 3, 2014 at 12:15
aaron-bond
3,3494 gold badges28 silver badges41 bronze badges
4 Comments
LefterisL
Yeap figured that out, still nothing though. Players div is filled fine, agonas nothing
aaron-bond
How about putting the code you need in the document load event?
LefterisL
Not familiar with the method, let me look it up and give it a try
aaron-bond
In a header script tag add: $( function () { //doStuff } ); You can find more here: api.jquery.com/ready
Try replacing:
setInterval( refreshAgonas, 5000);
With this:
setInterval(function(){ refreshAgonas()}, 5000);
answered Jan 3, 2014 at 12:12
cretzzzu3000
2211 silver badge7 bronze badges
lang-js