I am sending two different JSON array as response from servlet to jquery(ajax call).
Say jsonarray1
["E1134","2015-08-22 00:00:00","SK5012","2015-08-21 00:00:00","1621122","2015-08-01 00:00:00","2"]
Need to pass these to some text fields like E1134 -- Empid text field etc.,
jsonarray2
[{"slno":"1","itemname":"MCB DOUBLE POLE 10A -LEGRAND","itemcode":"2102MCBAC2P10A04","supplier":"SREE KUMAR AGENCIES","receivedqty":"200","rejectedqty":"0","acceptedqty":"200"},{"slno":"2","itemname":"MCB DOUBLE POLE 10A DC -LEGRAND","itemcode":"2102MCBDC2P10A04","supplier":"SREE KUMAR AGENCIES","receivedqty":"106","rejectedqty":"0","acceptedqty":"106"}]
These response will be passed to table like
$.each(responseJson, function(key,value) {
var rowNew = $("<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>");
rowNew.children().eq(0).html('<img src="idata.gif" height="42" width="42" alt="idata" class="popup-trigger">');
rowNew.children().eq(1).append(i);
rowNew.children().eq(2).text(value['itemname']);
rowNew.children().eq(3).text(value['itemcode']);
rowNew.children().eq(4).text(value['receivedqty']);
rowNew.children().eq(5).text(value['rejectedqty']);
rowNew.children().eq(6).text(value['acceptedqty']);
rowNew.children().eq(7).html('<input type="text" class="tb1"/>');
rowNew.appendTo(table1);
i++;
});
jsonarray1 needs to be populated in some text fields. jsonarray2 needs to be populated in table
I am struck with how to get those separately so that I can pass to the required fields. For example response1 for text fields and response2 for tables. Please someone help me on this
try{
Connection con=QCConProvider.getConnection();
PreparedStatement ps=con.prepareStatement("query1");
ResultSet rs=ps.executeQuery();
if (!rs.next() ) {
System.out.println("no data");
}else {
existqcmaster = true;
irepno = rs.getString("valu");
cdate = rs.getString("cdate");
vinvno = rs.getString("vinvno");
vinvdt = rs.getString("vinvdt");
pono = rs.getString("pono");
podt = rs.getString("podt");
unit = rs.getString("unit");
}
//close all connection here.
}catch(Exception e){
System.out.println(e);
}
JSONArray masterdata = new JSONArray();//o/p1 - should send back to ajax
masterdata.put(irepno);
//pass all values to masterdata
System.out.println(masterdata);
System.out.println(masterdata.length());
if (existqcmaster) {
System.out.println("qc details available");
ArrayList<Elements> inspdata = new ArrayList<Elements>();
inspdata=Fetchinsp.getElements(irepno);
Gson gson = new Gson();
JsonElement element = gson.toJsonTree(inspdata, new TypeToken<List<Elements>>() {}.getType());
JsonArray jsonArray = element.getAsJsonArray();
response.getWriter().print(jsonArray); // o/p2 - should send back to ajax
}
response.setContentType("application/json");
// response.getWriter().print(masterdata);
}
}