未捕获的 TypeError jqute
Uncaught TypeError jqute
我正在尝试制作一个非常简单的 html tableTree。我没有 html/javascript 编程方面的经验,因此我正在遍历 google 以查找有关我正在尝试实现的目标的示例。
我目前正在尝试找到一种将 json 文件传递到 html 文档的简单方法,并且我通过自己完成该代码部分并使用 ajax 和 jquery。
但是我找到了一个使用 jqote2 的例子,虽然实现这个例子给我一个错误 "Uncaught TypeError: undefined is not a function"。我想我错过了一些东西,虽然我不知道是什么,所以我希望我能在这里得到一些帮助:)
<!DOCTYPE html>
<html>
<head>
<script src="jquery/jquery-1.11.2.min.js"></script>
<script src="jqote2/jquery.jqote2.js"></script>
<script type="text/html" id="template">
<![CDATA[
<tr>
<td class="no"><%= j+1 %></td>
<td class="title"><%= this.Title %></td>
</tr>
]]>
</script>
<!-- 2 load the theme CSS file -->
<title>Test</title>
</head>
<body>
<script type="text/javascript">
var jsondata = [{"Title": "Dr.", "Surname": "House", "Firstname": "Geronimo"},{"Title": "Mr.", "Surname": "Franklin", "Firstname": "Benjamin"}];
// Now call jQote on the template providing your json data
$('#template').jqote(jsondata).appendTo($('#users'));
</script>
<div>
<table id="users"></table>
</div>
</body>
</html>
我根据 http://aefxx.com/jquery-plugin/jqote/
中的示例构建了此代码
当 运行 此代码时,我在
上收到错误
$('#template').jqote(jsondata).appendTo($('#users'));
所以我错过了什么 :) 我检查过包含的文件确实存在并且路径正确。
您在 CData 部分有问题
“<”和“&”等字符在 XML 个元素中是非法的。
“<”将产生错误,因为解析器将其解释为新元素的开始。
“&”将产生错误,因为解析器将其解释为字符实体的开头。
一些文本,例如 JavaScript 代码,包含大量“<”或“&”字符。为避免错误,脚本代码可以定义为 CDATA。
解析器会忽略 CDATA 部分中的所有内容。
移动你不能像你那样写字符串
http://www.w3schools.com/xml/xml_cdata.asp
从 json 对象绘制 table 会像这样
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.11.2.min.js"></script>
<!-- 2 load the theme CSS file -->
<title>Test</title>
</head>
<script type="text/javascript">
var jsondata = [{"Title": "Dr.", "Surname": "House", "Firstname": "Geronimo"},{"Title": "Mr.", "Surname": "Franklin", "Firstname": "Benjamin"}];
// Now call jQote on the template providing your json data
$( document ).ready(function() {
$.each( jsondata, function( key, value ) {
$.each( value, function( k, v ) {
$("#"+k).html(v);
});
});
});
</script>
<body>
<table>
<tr>
<td id="Title"></td>
<td id="Surname"></td>
<td id="House"></td>
<td id="Firstname"></td>
</tr>
</table>
</body>
</html>
第一个循环会将对象切割成数组,第二个循环会让您获取键和值,然后用它们做您想做的事^_^ 希望对您有所帮助
我正在尝试制作一个非常简单的 html tableTree。我没有 html/javascript 编程方面的经验,因此我正在遍历 google 以查找有关我正在尝试实现的目标的示例。
我目前正在尝试找到一种将 json 文件传递到 html 文档的简单方法,并且我通过自己完成该代码部分并使用 ajax 和 jquery。
但是我找到了一个使用 jqote2 的例子,虽然实现这个例子给我一个错误 "Uncaught TypeError: undefined is not a function"。我想我错过了一些东西,虽然我不知道是什么,所以我希望我能在这里得到一些帮助:)
<!DOCTYPE html>
<html>
<head>
<script src="jquery/jquery-1.11.2.min.js"></script>
<script src="jqote2/jquery.jqote2.js"></script>
<script type="text/html" id="template">
<![CDATA[
<tr>
<td class="no"><%= j+1 %></td>
<td class="title"><%= this.Title %></td>
</tr>
]]>
</script>
<!-- 2 load the theme CSS file -->
<title>Test</title>
</head>
<body>
<script type="text/javascript">
var jsondata = [{"Title": "Dr.", "Surname": "House", "Firstname": "Geronimo"},{"Title": "Mr.", "Surname": "Franklin", "Firstname": "Benjamin"}];
// Now call jQote on the template providing your json data
$('#template').jqote(jsondata).appendTo($('#users'));
</script>
<div>
<table id="users"></table>
</div>
</body>
</html>
我根据 http://aefxx.com/jquery-plugin/jqote/
中的示例构建了此代码当 运行 此代码时,我在
上收到错误$('#template').jqote(jsondata).appendTo($('#users'));
所以我错过了什么 :) 我检查过包含的文件确实存在并且路径正确。
您在 CData 部分有问题 “<”和“&”等字符在 XML 个元素中是非法的。
“<”将产生错误,因为解析器将其解释为新元素的开始。
“&”将产生错误,因为解析器将其解释为字符实体的开头。
一些文本,例如 JavaScript 代码,包含大量“<”或“&”字符。为避免错误,脚本代码可以定义为 CDATA。
解析器会忽略 CDATA 部分中的所有内容。 移动你不能像你那样写字符串
http://www.w3schools.com/xml/xml_cdata.asp
从 json 对象绘制 table 会像这样
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.11.2.min.js"></script>
<!-- 2 load the theme CSS file -->
<title>Test</title>
</head>
<script type="text/javascript">
var jsondata = [{"Title": "Dr.", "Surname": "House", "Firstname": "Geronimo"},{"Title": "Mr.", "Surname": "Franklin", "Firstname": "Benjamin"}];
// Now call jQote on the template providing your json data
$( document ).ready(function() {
$.each( jsondata, function( key, value ) {
$.each( value, function( k, v ) {
$("#"+k).html(v);
});
});
});
</script>
<body>
<table>
<tr>
<td id="Title"></td>
<td id="Surname"></td>
<td id="House"></td>
<td id="Firstname"></td>
</tr>
</table>
</body>
</html>
第一个循环会将对象切割成数组,第二个循环会让您获取键和值,然后用它们做您想做的事^_^ 希望对您有所帮助