Display the result of Jquey ajax get call

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)

  1. <table id="display"></table>
  2. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
  3. <script>
  4.     $(document).ready(function(){
  5.         $('[name="btn2"]').click(function(){
  6.             $.ajax({
  7.                 beforeSend: function(x) {
  8.                     if (x && x.overrideMimeType) {
  9.                         x.overrideMimeType("application/j-son;charset=UTF-8");
  10.                     }
  11.                 },
  12.                 type: "GET",
  13.                 dataType: "json",
  14.                 contentType: "application/json;charset=utf-8",
  15.                 url: "http://localhost:7080/airavata-registry-rest-services/registry/api/get/hostdescriptors",
  16.                 success: function(responseData, status, settings) {
  17. //                    alert(data);
  18. //                    var data = JSON.stringify(responseData);
  19. //                    $.each(data, function(key, val) {
  20. //                        var tr=$('<tr></tr>');
  21. //                        $.each(val, function(k, v){
  22. //                            $('<td>'+v+'</td>').appendTo(tr);
  23. //                        });
  24. //                        tr.appendTo('#display');
  25. //                    });
  26.                 },
  27.                 error: function(ajaxrequest, ajaxOptions, thrownError){
  28.                     alert(thrownError);
  29.                 }
  30.             }).done(function(msg) {
  31.                         alert( "Data Saved: " + JSON.stringify(msg));
  32.                     });
  33.         });
  34.     });
  35. </script>
The Jason response that I'm getting from the service is:

  1. {
  2.    "hostDescriptions":[
  3.       {
  4.          "hostAddress":"faa",
  5.          "hostType":"HostDescriptionType",
  6.          "hostname":"adsff"
  7.       },
  8.       {
  9.          "hostAddress":"asdf",
  10.          "hostType":"HostDescriptionType",
  11.          "hostname":"asdf"
  12.       },
  13.       {
  14.          "hostAddress":"asdf2",
  15.          "hostType":"HostDescriptionType",
  16.          "hostname":"asdf2"
  17.       },
  18.       {
  19.          "globusGateKeeperEndPoint":"grid-ember.ncsa.teragrid.org:2811/",
  20.          "gridFTPEndPoint":"grid-ember.ncsa.teragrid.org:2811/",
  21.          "hostAddress":"ember.ncsa.teragrid.org",
  22.          "hostType":"GlobusHostType",
  23.          "hostname":"ember"
  24.       },
  25.       {
  26.          "globusGateKeeperEndPoint":"gatekeeper.ranger.tacc.teragrid.org:2119/jobmanager-sge",
  27.          "gridFTPEndPoint":"gatekeeper.ranger.tacc.teragrid.org:2119/jobmanager-sge",
  28.          "hostAddress":"gatekeeper2.ranger.tacc.teragrid.org",
  29.          "hostType":"GlobusHostType",
  30.          "hostname":"gram"
  31.       },
  32.       {
  33.          "hostAddress":"asdfafda",
  34.          "hostType":"HostDescriptionType",
  35.          "hostname":"z8"
  36.       }
  37.    ]
  38. }