Display the result of Jquey ajax get call
I am doing a jquery ajax call to get some data from a service. The response is in Jason format. My code looks like below. I want to display the results I obtained in a html table. I am able to see the alert once the response comes back but when I try to write the data to a table, the data is not displayed (I have commented the code segment out)
- <table id="display"></table>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
- <script>
- $(document).ready(function(){
- $('[name="btn2"]').click(function(){
- $.ajax({
- beforeSend: function(x) {
- if (x && x.overrideMimeType) {
- x.overrideMimeType("application/j-son;charset=UTF-8");
- }
- },
- type: "GET",
- dataType: "json",
- contentType: "application/json;charset=utf-8",
- url: "http://localhost:7080/airavata-registry-rest-services/registry/api/get/hostdescriptors",
- success: function(responseData, status, settings) {
- // alert(data);
- // var data = JSON.stringify(responseData);
- // $.each(data, function(key, val) {
- // var tr=$('<tr></tr>');
- // $.each(val, function(k, v){
- // $('<td>'+v+'</td>').appendTo(tr);
- // });
- // tr.appendTo('#display');
- // });
- },
- error: function(ajaxrequest, ajaxOptions, thrownError){
- alert(thrownError);
- }
- }).done(function(msg) {
- alert( "Data Saved: " + JSON.stringify(msg));
- });
- });
- });
- </script>
The Jason response that I'm getting from the service is:
- {
- "hostDescriptions":[
- {
- "hostAddress":"faa",
- "hostType":"HostDescriptionType",
- "hostname":"adsff"
- },
- {
- "hostAddress":"asdf",
- "hostType":"HostDescriptionType",
- "hostname":"asdf"
- },
- {
- "hostAddress":"asdf2",
- "hostType":"HostDescriptionType",
- "hostname":"asdf2"
- },
- {
- "globusGateKeeperEndPoint":"grid-ember.ncsa.teragrid.org:2811/",
- "gridFTPEndPoint":"grid-ember.ncsa.teragrid.org:2811/",
- "hostAddress":"ember.ncsa.teragrid.org",
- "hostType":"GlobusHostType",
- "hostname":"ember"
- },
- {
- "globusGateKeeperEndPoint":"gatekeeper.ranger.tacc.teragrid.org:2119/jobmanager-sge",
- "gridFTPEndPoint":"gatekeeper.ranger.tacc.teragrid.org:2119/jobmanager-sge",
- "hostAddress":"gatekeeper2.ranger.tacc.teragrid.org",
- "hostType":"GlobusHostType",
- "hostname":"gram"
- },
- {
- "hostAddress":"asdfafda",
- "hostType":"HostDescriptionType",
- "hostname":"z8"
- }
- ]
- }