http.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var http;
  2. if (!http)
  3. http = {};
  4. /**
  5. * post提交事件
  6. * @param url 地址
  7. * @param params 参数
  8. * @param msg 提示信息
  9. * @param success 成功回调
  10. */
  11. http.post = function (url, params, msg, success, error) {
  12. if (msg == null)
  13. msg = '加载中...';
  14. $.blockUI(
  15. {
  16. message: msg,
  17. baseZ: 2000,
  18. css: {
  19. border: 'none',
  20. padding: '15px',
  21. backgroundColor: 'white',
  22. width: "300px",
  23. opacity: .5,
  24. color: 'black'
  25. }
  26. });
  27. $.ajax({
  28. type: "POST",
  29. url: url,
  30. data: params,
  31. contentType: "application/json",
  32. success: function (data) {
  33. $.unblockUI();
  34. if (success != null) {
  35. success(data);
  36. }
  37. }, error: function (data) {
  38. $.unblockUI();
  39. if (error != null) {
  40. error(data);
  41. }
  42. }
  43. });
  44. }
  45. http.get = function (url, msg, success, error) {
  46. if (msg == null)
  47. msg = '加载中...';
  48. $.blockUI(
  49. {
  50. message: msg,
  51. baseZ: 2000,
  52. css: {
  53. border: 'none',
  54. padding: '15px',
  55. backgroundColor: 'white',
  56. width: "300px",
  57. opacity: .5,
  58. color: 'black'
  59. }
  60. });
  61. $.ajax({
  62. type: "GET",
  63. url: url,
  64. contentType: "application/json",
  65. success: function (data) {
  66. $.unblockUI();
  67. if (success != null) {
  68. success(data);
  69. }
  70. },
  71. error: function (data) {
  72. $.unblockUI();
  73. if (error != null) {
  74. error(data);
  75. }
  76. }
  77. });
  78. }