java - Getting json response from servlet and display in jsp table? -


i calling servlet list of objects database , list returning json servlet. same json response displayed in jsp table below.

servlet code:

        string json = new gson().tojson(resultlist);          response.setcontenttype("application/json"); //here have data , came know debugging          response.setcharacterencoding("utf-8");         response.getwriter().write(json); 

jquery code:

$.ajax({     type: "get",     url: "./datafetchcontroller",     success: function(responsejson) {  console.log(responsejson); //it not printing result on firebug console          var master = $(this).parents("table.mytable");          $.each(responsejson, function(index, contact) {    // iterate on json array.             // new row based on prototype row             var prot = master.find(".prototype").clone();             prot.attr("class", "");             prot.find("#myname").attr("value", contact.name);             prot.find("#mylastname").attr("value", contact.lastname);              //master.find("tbody").append(prot);             jquery('table.mytable tr:last').before(prot);         });     },     error: function(ob,errstr) {         $('#contactform #formprogress').html('');         $('#contactform #formprogress').html('<img src="./public/images/error.png" /> <span style="color:red">save not successful. try again.</span>');     } }); 

i not getting json result. tried printing using console no result in servlet has data returned database , verified using debug. missing here?

thanks!

i not see "datatype" in ajax request like:

datatype: 'json'

try adding it.

so, become:

$.ajax({  type: "get",  url: "./datafetchcontroller",  success: function(responsejson) {        //alert , success handler  },  datatype: 'json',  error : function(){    // error handler  }); 

datatype type of data you're expecting server


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -