12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var baseUrl = '';
  2. var timeout = 60 * 1000;
  3. /**
  4. * Ajax
  5. * @constructor
  6. */
  7. function Ajax() {
  8. }
  9. Ajax.get = _get;
  10. Ajax.post = _post;
  11. /**
  12. * get
  13. * @param url
  14. * @param params
  15. * @return {*|{readyState, getResponseHeader, getAllResponseHeaders, setRequestHeader, overrideMimeType, statusCode, abort}}
  16. * @private
  17. */
  18. function _get(url, params) {
  19. return $.ajax({
  20. url: baseUrl + url,
  21. method: 'GET',
  22. timeout: timeout,
  23. data: params,
  24. dataType: 'json',
  25. cache: false,
  26. success: function (response) {
  27. },
  28. error: function (XMLHttpRequest, textStatus, errorThrown) {
  29. alert('网络加载失败,请稍后重试!');
  30. }
  31. })
  32. }
  33. /**
  34. * post
  35. * @param url
  36. * @param params
  37. * @return {*|{readyState, getResponseHeader, getAllResponseHeaders, setRequestHeader, overrideMimeType, statusCode, abort}}
  38. * @private
  39. */
  40. function _post(url, params) {
  41. return $.ajax({
  42. url: baseUrl + url,
  43. method: 'POST',
  44. timeout: timeout,
  45. data: params,
  46. cache: false,
  47. success: function (response) {
  48. },
  49. error: function (XMLHttpRequest, textStatus, errorThrown) {
  50. alert('网络加载失败,请稍后重试!');
  51. }
  52. })
  53. }