data.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function data_query() {
  2. str = '<table border="1" width="100%">';
  3. str += '<tr><td>id:</td><td><input type="text" id="id" style="width:95%"/></td></tr>';
  4. str += '<tr><td>type:</td><td>';
  5. str += '<select id="type">';
  6. str += '<option value="appInfo">appInfo</option>';
  7. str += '<option value="catagoryInfo">catagoryInfo</option>';
  8. str += '<option value="fileInfo">fileInfo</option>';
  9. str += '<option value="appCatagoryPermission">appCatagoryPermission</option>';
  10. str += '<option value="appCatagoryAdmin">appCatagoryAdmin</option>';
  11. str += '<option value="log">log</option>';
  12. str += '</select>';
  13. str += '</td></tr>';
  14. str += '<tr><td colspan="2"><button id="get">get</button>&nbsp;<button id="put">put</button>&nbsp;<button id="post">post</button>&nbsp;<button id="uuid">UUID</button></td></tr>';
  15. str += '<tr><td colspan="2"><textarea id="data" style="width:95%;height:500px"/></td></tr>';
  16. str += '</table>';
  17. $('#content').html(str);
  18. $('#result').html('');
  19. $('#get', '#content').click(function() {
  20. data_get($('#id').val(), $('#type').val());
  21. });
  22. $('#put', '#content').click(function() {
  23. data_put($('#id').val(), $('#type').val());
  24. });
  25. $('#post', '#content').click(function() {
  26. data_post($('#id').val(), $('#type').val());
  27. });
  28. $('#uuid', '#content').click(function() {
  29. get_uuid();
  30. });
  31. }
  32. function get_uuid( ) {
  33. $('#data', '#content').val('');
  34. $.ajax({
  35. type : 'get',
  36. dataType : 'json',
  37. url : '../jaxrs/uuid/random',
  38. xhrFields : {
  39. 'withCredentials' : true
  40. },
  41. crossDomain : true
  42. }).done(function(data) {
  43. if (data.type == 'success') {
  44. $('#content').html(JSON.stringify(json.data));
  45. } else {
  46. failure(data);
  47. }
  48. });
  49. }
  50. function data_get(id, type) {
  51. $('#data', '#content').val('');
  52. $.ajax({
  53. type : 'get',
  54. dataType : 'json',
  55. contentType : 'application/json; charset=utf-8',
  56. url : '../jaxrs/' + type + '/' + id,
  57. xhrFields : {
  58. 'withCredentials' : true
  59. },
  60. crossDomain : true
  61. }).done(function(json) {
  62. $('#result').html(JSON.stringify(data, null, 4));
  63. if (json.type == 'success') {
  64. $('#data', '#content').val(JSON.stringify(json.data, null, 4));
  65. } else {
  66. failure(data);
  67. }
  68. }).fail(function(data) {
  69. failure(data);
  70. });
  71. }
  72. function data_put( id, type ) {
  73. $.ajax({
  74. type : 'put',
  75. dataType : 'json',
  76. contentType : 'application/json; charset=utf-8',
  77. url : '../jaxrs/' + type + '/' + id,
  78. xhrFields : {
  79. 'withCredentials' : true
  80. },
  81. data : JSON.stringify($.parseJSON($('#data', '#content').val())),
  82. crossDomain : true
  83. }).done(function(data) {
  84. $('#result').html(JSON.stringify(data.data, null, 4));
  85. });
  86. }
  87. function data_post( id, type ) {
  88. $.ajax({
  89. type : 'post',
  90. dataType : 'json',
  91. contentType : 'application/json; charset=utf-8',
  92. url : '../jaxrs/' + type ,
  93. xhrFields : {
  94. 'withCredentials' : true
  95. },
  96. data : JSON.stringify($.parseJSON($('#data', '#content').val())),
  97. crossDomain : true
  98. }).done(function(data) {
  99. $('#result').html(JSON.stringify(data.data, null, 4));
  100. });
  101. }