144
rated 0 times
[
145]
[
1]
/ answers: 1 / hits: 7208
/ 11 Years ago, sat, december 28, 2013, 12:00:00
I am new to jQuery. I am creating the json string in my servlet using gson-2.2.3.jar
:
Gson gs = new Gson();
String json = gs.toJson(names);
System.out.println(json);
PrintWriter out = resp.getWriter();
out.println(json);
out.close();
Below are the two commented codes I tried for binding the json string with drop-down but none of them works:
$.ajax({
type:POST,
url: DropDownController,
success: function(result){
alert(result);
/* for (var id in result) {
$(#drpDown).append('<option value='+id+'>'+id+'</option>');
} */
/* $.each(result, function (index, value) {
$(#drpDown).append('<option value='+value.id+'>'+value.name+'</option>');
}); */
}
});
The alert message box present in the success
displays the json string in below format:
[Alabama,California,Alaska,Ohio]
Kindly let me know how to bind the above json string
data with the drop-down.
More From » jquery