I called a servlet through ajax call on widow.load() event ..But when i want to show the value got after success of ajax call in alert box it is showing [object XMLDocument] i dont know why .this is the first time i am using ajax call.
Here is my ajax call code...`
$(window).load(function() {
$.ajax({
type: 'GET',
url: 'Sites',
datatype:'text',
success: function(data) {
alert(data);
debugger;
var city=data;
for(var i in city)
{
output ='<input type="checkbox" id="'+city[i]+'" name="'+city[i]+'" value="'+city[i]+'" />'+city[i]+'<br />'
}
console.log(output)
}
});
});
And here is my servlet code from where i sending data in arraylist formate.
PrintWriter out = response.getWriter();
ArrayList calltype = new ArrayList();
try {
String strQuery = "";
ResultSet rs = null;
conexion conexiondb = new conexion();
conexiondb.Conectar();
strQuery = "Select * from sites";
rs = conexiondb.Consulta(strQuery);
while (rs.next()) {
String toc = rs.getString("sites");
calltype.add(toc);
}
out.print(calltype);
System.out.println(calltype);
out.close();
} catch (Exception e) {
// display stack trace in the browser
System.out.println(e);
}
Any help on this will be appreciated .. Thanks in advance..