I've got a java servlet to connect to a MS SQL 2008 database and retrieve info, pass the resultset on to a class to convert it to jsonarray and then return that info.
Here is a sample of the returned info when I browse to the class from my browser using http://localhost:8080/KReport/GetInfo?q=va-sql2008 :
[{"machineinfo":{"DefaultGateway":"172.24.1.2","groupName":"servers.headoffice.vasa","ChassisManufacturer":"No Enclosure","DhcpEnabled":2,"LoginName":"","MotherboardProductCode":"440BX Desktop Reference Platform","MaxMemorySlots":"15","Machine_GroupID":"va-sql2008dev.servers.headoffice.vasa","timezoneOffset":-120,"ChassisSerialNumber":"None","MajorVersion":6,"MotherboardVersion":"None","MaxMemorySize":"256 GB","Manufacturer":"VMware, Inc.","MacAddr":"00-50-56-9F-00-11","ProductName":"VMware Virtual Platform","agentGuid":871664384736872,"OsInfo":"R2 Server Standard x64 Edition Build 7600","PrimaryWinsServer":"172.24.1.9","SysSerialNumber":"VMware-42 1f 09 c3 bd 8c ad 60-22 e4 50 1c 35 52 76 fe","OsType":"2008","MotherboardManufacturer":"Intel Corporation","ipv6Address":"[fe80::edf0:d1bd:6ef8:a17d%11]","MachineVersion":"None","IpAddress":"172.24.1.184","DnsServer1":"172.24.1.22","DnsServer2":"172.24.1.29","ComputerName":"va-sql2008dev","ChassisAssetTag":"No Asset Tag","ChassisType":"Other","MotherboardSerialNumber":"None","SubnetMask":"255.255.255.0","MinorVersion":1,"agentInstGuid":"KSY99906876289809604","WinsEnabled":1,"ConnectionGatewayIp":"172.24.1.184","machName":"va-sql2008dev","ChassisVersion":"N\/A","BusSpeed":"0 MHz"}},{"machineinfo":{"DefaultGateway":"172.24.1.2","groupName":"servers.headoffice.vasa","ChassisManufacturer":"No Enclosure","DhcpEnabled":2,"LoginName":"","MotherboardProductCode":"440BX Desktop Reference Platform","MaxMemorySlots":"15","Machine_GroupID":"va-sql2008dev.servers.headoffice.vasa","timezoneOffset":-120,"ChassisSerialNumber":"None","MajorVersion":6,"MotherboardVersion":"None","MaxMemorySize":"256 GB","Manufacturer":"VMware, Inc.","MacAddr":"00-50-56-9F-00-11","ProductName":"VMware Virtual Platform","agentGuid":871664384736872,"OsInfo":"R2 Server Standard x64 Edition Build 7600","PrimaryWinsServer":"172.24.1.9","SysSerialNumber":"VMware-42 1f 09 c3 bd 8c ad 60-22 e4 50 1c 35 52 76 fe","OsType":"2008","MotherboardManufacturer":"Intel Corporation","ipv6Address":"[fe80::edf0:d1bd:6ef8:a17d%11]","MachineVersion":"None","IpAddress":"172.24.1.184","DnsServer1":"172.24.1.22","DnsServer2":"172.24.1.29","ComputerName":"va-sql2008dev","ChassisAssetTag":"No Asset Tag","ChassisType":"Other","MotherboardSerialNumber":"None","SubnetMask":"255.255.255.0","MinorVersion":1,"agentInstGuid":"KSY99906876289809604","WinsEnabled":1,"ConnectionGatewayIp":"172.24.1.184","machName":"va-sql2008dev","ChassisVersion":"N\/A","BusSpeed":"0 MHz"}}]
There are 2 machines listed in there (if you search for machineinfo in there you will find 2 entries). I have verified this returned info on JSONLint and it checks out as valid json.
My servlet returns the info via response.getWriter().write(njson.toString());
but I can't seem to figure out how to display this info using javascript on another page.
My last attempt was using :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script type="text/javascript">
$.ajax({
url:'http://localhost:8080/KReport/GetInfo?q=va-sql2008',
dataType:'json',
type:'GET',
success:function(data){
console.log(data);
},
error:function(jxhr){
console.log(jxhr.responseText);
}
});
</script>
</html>
but that didn't work - just a blank screen.
Any help would be appreciated?