javascript - Uncaught SyntaxError: Unexpected token (Script Ajax Call) -
i'm doing in cq5
, component connect servlet , info:
output servlet (json format)= [{"text":"a","value":10},{"text":"b","value":20}]
for show , b in drop down menu.
this 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 options (select), javascript in jsp of component:
<script type="text/javascript"> //get reference select element $select = $('#options'); //request json data , parse select element $.ajax({ url: '/bin/company/repo', datatype:'json', success:function(data){ //clear current content of select $select.html(''); //iterate on data , append select option $.each(data, function(text, value){ $select.append('<option id="' + value.value + '">' + value.text + '</option>'); }); }, error:function(){ //if there error append 'none available' option $select.html('<option id="-1">none available</option>'); } }); </script>
but uncaught typeerror undefined not function
. maybe have error of syntax in script code. how can solve?
there conflict between 2 jquery:
we can delete 1 or modify code this:
<script type="text/javascript"> var j = jquery.noconflict(); j(document).ready(function(){ //get reference select element //request json data , parse select element j.ajax({ url: '/bin/company/repo', datatype:'json', success:function(data){ //clear current content of select j('#abcd').html(''); //iterate on data , append select option jquery.each(data, function(text, value){ j('#abcd').append('<option id="' + value.value + '">' + value.text + '</option>'); }); }, error:function(){ //if there error append 'none available' option j('#abcd').html('<option id="-1">none available</option>'); } }); })
Comments
Post a Comment