【发布时间】:2015-04-01 08:47:13
【问题描述】:
我正在使用CQ5,这是一个与 servlet 连接并获取此信息的组件:
输出 Servlet(json 格式)= [{"text":"A","value":10},{"text":"B","value":20}]
用于在下拉菜单中显示 A 和 B。
这是我的 html 代码:
<div>
<form action="/bin/company/repo" method="post">
<select id="options">
</select>
<input type="submit" id="send" value="Send">
</form>
<p id="demo"></p>
</div>
为了插入选项(选择),我在组件的jsp中执行此javascript:
<script type="text/javascript">
//get a reference to the select element
$select = $('#options');
//request the JSON data and parse into the select element
$.ajax({
url: '/bin/company/repo',
dataType:'JSON',
success:function(data){
//clear the current content of the select
$select.html('');
//iterate over the data and append a select option
$.each(data, function(text, value){
$select.append('<option id="' + value.value + '">' + value.text + '</option>');
});
},
error:function(){
//if there is an error append a 'none available' option
$select.html('<option id="-1">none available</option>');
}
});
</script>
但我得到Uncaught typeerror undefined is not a function。也许我的脚本代码中有语法错误。我该如何解决?
【问题讨论】:
-
其真实但未捕获的类型错误 undefined is not a function is the problem now 是输入问题时出错:I
-
好吧...本来可以回答
-
你的调试器应该告诉你错误在哪一行。
-
您正在为您的选择选项使用 id,应该是 class,因为它不是唯一的。
-
before error:function(){ in " }," 在这个地方我得到 Uncaught typeerror undefined is not a function 根据调试器。
标签: javascript jquery ajax servlets aem