i'm doing in CQ5, a component that connect with a servlet and get this info:
Output Servlet (json format)= [{"text":"A","value":10},{"text":"B","value":20}]
for show A and B in a drop down menu.
This my html code:
<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>
For insert the options (select), i do this javascript in the jsp of component:
<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>
But I get Uncaught typeerror undefined is not a function. Maybe I have an error of syntax in my script code. How can I solve?