本文档中的最后一个js函数(refreshuserinfo)在Firefox中运行良好,但在Chrome中它是一个不起作用的Safari。
控制台告诉我: 未捕获的ReferenceError:未定义refreshuserinfo 和未捕获的SyntaxError:意外的标识符
我不知道为什么这个功能在这些浏览器中起作用
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,300italic,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Exo+2:400,100,200' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="meldung"></div>
<div class="logo">
Quiz
</div>
<div class="wrapper-menu">
<div id="element">
<div id="element2"></div>
<!--Hier wird das JSON eingefügt-->
</div>
<div class="wrapper-menu-inner">
<hr>
<a onclick="shuffle()" href="#"><div>Spielen</div></a>
<a href="kategorien.html"><div>Kategorie wählen</div></a>
<a href="#" onclick="randomCategory()"><div>Zufällige Kategorie spielen</div></a>
<hr>
<a href="editor_category.html"><div>Kategorie erstellen</div></a>
<a href="editor_question.html"><div>Frage erstellen</div></a>
<a href="#" onclick="logout()"><div>Abmelden</div></a>
</div>
</div>
function refreshuserinfo() {
$('#refresher').addClass("fa-spin");
setTimeout(function()$('#refresher').removeClass('fa-spin'),3000);
$.ajax ({
url:'http://marcelkipp.com/quizapp/userinfo.php?user_id='+localStorage.getItem('user_id'),
dataType: 'json',
type: 'get',
cache: false,
success:function(data) {
console.log('JSON erfolgreich ausgelesen!');
var category = data.category_title;
if (category==null) category = "Keine Kategorie gewählt";
localStorage.setItem('points', data.points);
localStorage.setItem('total_questions',data.number_pq);
$('#element2').empty();
$('#element2').append("<a href='#'><div class='menu_username nopointer'>"+localStorage.points+" Punkte</div></a>"+
"<a href='#'><div class='menu_username nopointer'>"+localStorage.total_questions+" gespielte Fragen</div></a>")
}
});
}
</script>
</body>
</html>
答案 0 :(得分:0)
下面:
setTimeout(function()$('#refresher').removeClass('fa-spin'),3000);
缺少一对花括号,应该是:
setTimeout(function () {$('#refresher').removeClass('fa-spin');}, 3000);
该修复程序修复了这两个错误。 refreshuserinfo()
未定义,因为引用错误破坏了代码。