jest_common.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. function failure(data) {
  2. console.log(data);
  3. alert(data.message);
  4. }
  5. function splitValue(str) {
  6. if (str) {
  7. if (str.length > 0) {
  8. return str.split(',');
  9. }
  10. }
  11. return [];
  12. }
  13. function joinValue(o, split) {
  14. var s = ',';
  15. if (split) {
  16. s = '' + split;
  17. }
  18. if (o) {
  19. if (toString.apply(o) === '[object Array]') {
  20. return o.join(s);
  21. }
  22. }
  23. return o;
  24. }
  25. function send_get_request( url ){
  26. $.ajax({
  27. type : 'get',
  28. dataType : 'json',
  29. contentType : 'application/json; charset=utf-8',
  30. url : url,
  31. xhrFields : {
  32. 'withCredentials' : true
  33. },
  34. crossDomain : true
  35. }).done(function(json) {
  36. $('#result').html( JSON.stringify( json, null, 4) );
  37. }).fail(function(json) {
  38. failure(json);
  39. });
  40. }
  41. function send_post_request( url ){
  42. var content = $('#content').val();
  43. if( content == null || content == undefined || content == "" ){
  44. alert("请输入content");
  45. return false;
  46. }
  47. $.ajax({
  48. type : 'post',
  49. dataType : 'json',
  50. contentType : 'application/json; charset=utf-8',
  51. url : url ,
  52. xhrFields : {
  53. 'withCredentials' : true
  54. },
  55. data : JSON.stringify($.parseJSON( content )),
  56. crossDomain : true
  57. }).done(function(json) {
  58. $('#result').html(JSON.stringify(json.data, null, 4));
  59. });
  60. }
  61. function send_put_request( url ){
  62. var content = $('#content').val();
  63. if( content == null || content == undefined || content == "" ){
  64. alert("请输入content");
  65. return false;
  66. }
  67. $.ajax({
  68. type : 'put',
  69. dataType : 'json',
  70. contentType : 'application/json; charset=utf-8',
  71. url : url ,
  72. xhrFields : {
  73. 'withCredentials' : true
  74. },
  75. data : JSON.stringify($.parseJSON( content )),
  76. crossDomain : true
  77. }).done(function(json) {
  78. $('#result').html(JSON.stringify(json.data, null, 4));
  79. });
  80. }
  81. function send_delete_request( url, id ) {
  82. if( id == null || id == undefined || id == "" ){
  83. alert("请输入ID");
  84. return false;
  85. }
  86. $.ajax({
  87. type : 'delete',
  88. dataType : 'json',
  89. contentType : 'application/json; charset=utf-8',
  90. url : url + '/' + id ,
  91. xhrFields : { 'withCredentials' : true },
  92. crossDomain : true
  93. }).done(function(json) {
  94. $('#result').html(JSON.stringify( json.data, null, 4 ));
  95. });
  96. }
  97. function send_delete_request_as_url( url ) {
  98. if( id == null || id == undefined || id == "" ){
  99. alert("请输入ID");
  100. return false;
  101. }
  102. $.ajax({
  103. type : 'delete',
  104. dataType : 'json',
  105. contentType : 'application/json; charset=utf-8',
  106. url : url + '/' ,
  107. xhrFields : { 'withCredentials' : true },
  108. crossDomain : true
  109. }).done(function(json) {
  110. $('#result').html(JSON.stringify( json.data, null, 4 ));
  111. });
  112. }