我需要真正找到此错误的来源。我前几天暂时解决了它,但似乎每次我在JS文件中添加一个新函数我都会得到它。之前我只会在新功能上获得“Uncaught ReferenceError $ is not defined”,但现在它适用于所有这些功能。我还得到了一个“ncaught SyntaxError:Unexpected token<”但这至少就目前而言是次要问题。
索引文件
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery-draw.js"></script>
</head>
<h2>Players</h2>
<div class="players">
<script>
setInterval( refreshPlayers, 5000 );
var inRequest = false;
</script></div>
<h3>Please select the Game you would like to view</h3>
<div class="pickGame">
<script>
setInterval( viewGames, 5000 );
var inRequestT = false;
</script>
</div>
<h2>Game</h2>
<div class="agonas">
<script>
setInterval( refreshAgonas, 5000);
var inRequestG = false;
</script></div>
</html>
jquery-draw.js文件
function viewGames(){
if ( inRequestT ) {
return false;
}
inRequestT = true;
var load = $.get('drawgames.php');
$(".pickGame").html('Refreshing');
load.error(function() {
console.log("Mlkia kaneis");
$(".pickGame").html('failed to load');
// do something here if request failed
});
load.success(function( res ) {
console.log( "Success" );
$(".pickGame").html('<form method="post" action="viewgame.php">
<select name="gameNo">'+res+'</select>
<input type="submit" value="Choose Game">
</form>');
});
load.done(function() {
console.log( "Completed" );
inRequestT = 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;
});
}
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;
});
}
答案 0 :(得分:2)
问题在于:
$(".pickGame").html('<form method="post" action="viewgame.php">
<select name="gameNo">'+res+'</select>
<input type="submit" value="Choose Game">
</form>');
JavaScript不允许字符串中的原始换行符,除非您使用反斜杠转义它们。如果你在那里有它们,则无法解析整个脚本,也没有任何工作。
另外,你这样做:
var load = $.get('drawgames.php');
然后在error
上调用函数success
,done
和load
。 load
将引用jqXHR对象。他们没有error
或success
个函数(他们确实有done
函数)。您会混淆$.ajax
函数接受回调的{em>属性以及jqXHR
提供的函数。我建议使用reviewing the documentation以正确使用$.get
。
答案 1 :(得分:0)
这一切都需要在一条线上:
$(".pickGame").html('<form method="post" action="viewgame.php">
<select name="gameNo">'+res+'</select>
<input type="submit" value="Choose Game">
</form>');