test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. function doget() {
  2. var url = '../jaxrs/'+$("#url").val();
  3. alert(url);
  4. $.ajax({
  5. type : 'get',
  6. dataType : 'json',
  7. contentType : 'application/json; charset=utf-8',
  8. url : url,
  9. xhrFields : {
  10. 'withCredentials' : true
  11. },
  12. crossDomain : true
  13. }).done(function(json) {
  14. $('#result').html( JSON.stringify( json, null, 4) );
  15. }).fail(function(json) {
  16. failure(json);
  17. });
  18. }
  19. function dopost() {
  20. var url = '../jaxrs/'+$("#url").val();
  21. alert(url);
  22. $.ajax({
  23. type : 'post',
  24. dataType : 'json',
  25. contentType : 'application/json; charset=utf-8',
  26. url : url ,
  27. xhrFields : {
  28. 'withCredentials' : true
  29. },
  30. data : JSON.stringify($.parseJSON($('#content').val())),
  31. crossDomain : true
  32. }).done(function(json) {
  33. $('#result').html(JSON.stringify(json.data, null, 4));
  34. });
  35. }
  36. function doput() {
  37. var url = '../jaxrs/'+$("#url").val();
  38. alert(url);
  39. $.ajax({
  40. type : 'put',
  41. dataType : 'json',
  42. contentType : 'application/json; charset=utf-8',
  43. url : url ,
  44. xhrFields : {
  45. 'withCredentials' : true
  46. },
  47. data : JSON.stringify($.parseJSON($('#content').val())),
  48. crossDomain : true
  49. }).done(function(json) {
  50. $('#result').html(JSON.stringify(json.data, null, 4));
  51. });
  52. }
  53. function dodelete() {
  54. var url = '../jaxrs/'+$("#url").val();
  55. alert(url);
  56. $.ajax({
  57. type : 'delete',
  58. dataType : 'json',
  59. contentType : 'application/json; charset=utf-8',
  60. url : url,
  61. xhrFields : {
  62. 'withCredentials' : true
  63. },
  64. crossDomain : true
  65. }).done(function(json) {
  66. $('#result').html(JSON.stringify(json.data, null, 4));
  67. });
  68. }