未捕获的语法错误:意外的标识符.Firefox是有效的.铬不是
Uncaught SyntaxError: Unexpected identifier. Firefox works. Chrome not
本文档中的最后一个js函数(refreshuserinfo)在Firefox中运行良好,但在Chrome和Safari中则不起作用。
控制台显示:未捕获引用错误:未定义refreshuserinfo和不捕获语法错误:意外标识符
我不知道为什么这个功能在这些浏览器中不起作用
</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>
此处:
setTimeout(function()$('#refresher').removeClass('fa-spin'),3000);
缺少一对大括号,应该是:
setTimeout(function () {$('#refresher').removeClass('fa-spin');}, 3000);
该修复程序修复了这两个错误。refreshuserinfo()
未定义,因为引用错误破坏了代码。
相关文章:
- 滚动在Chrome中有效,但在Firefox或IE中无效
- 为什么这个按钮在IE中有效,但在Firefox中无效
- Javascript下载在firefox中停止,但在Chrome中有效
- JavaScript函数在Safari中有效,但在Firefox中找不到
- 禁用字段在IE中有效,但在Firefox中无效
- 在getJSON之后构建HTML在Safari中有效,但在Chrome或Firefox中无效
- 为什么对img标记的前向引用在Chrome上失败,但在FireFox和IE上有效
- Date对象在Chrome中有效,但在Safari、Firefox或IE中无效
- 如何在(javascript)Firefox插件中有效地存储传入数据
- 日期差异在Firefox和IE中有效,但在Chrome中返回NaN
- 为什么这段代码在FireFox和IE中不起作用,但在Chrome中却有效
- 为什么从位置哈希中选择下拉列表在 Chrome 上有效,但不适用于 Firefox、IE 或 Safari
- 图像大小调整在Chrome中有效,但在Firefox中则不然
- 有效的网页显示在WebKit浏览器和IE中,但不显示在Firefox中
- jQuery AJAX 调用在 Firefox 中有效,但在 IE 中不起作用 - 返回有效响应
- Mozilla Firefox表示未定义Referenceerror事件,没有任何解决方案有效
- 图像交换在Firefox中不起作用,但在Chrome和IE中有效
- Javascript切换图像边框在Firefox中有效,但不适用于IE
- Google Web Map 复选框在 Firefox 和 Chrome 中有效,但在 IE 中不起作用
- 为什么这个setInterval/document.write代码在Chrome上有效,但在Firefox上不起作用