init.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var genUrl = "http://39.98.35.167:9999";
  2. var baseUrl = "http://121.37.6.200:8088";
  3. // GET请求
  4. function getAjax(opts, data) {
  5. $.Deferred(function(){});
  6. return new Promise(function(resolve, reject) {
  7. $.ajax({
  8. url: opts.http + opts.url,
  9. type: opts.type,
  10. dataType: "json",
  11. data: data,
  12. headers: {
  13. "Authorization": opts.tok
  14. },
  15. error: function() {
  16. localStorage.removeItem("AjaxGen");
  17. localStorage.removeItem("ylToken");
  18. top.location.href = "../index.html";
  19. },
  20. success: function(dart) {
  21. if(dart.code == 401||dart.status == -1){
  22. localStorage.removeItem("AjaxGen");
  23. localStorage.removeItem("ylToken");
  24. top.location.href = "../index.html";
  25. }else{
  26. resolve(dart);
  27. }
  28. }
  29. });
  30. })
  31. }
  32. // POST请求
  33. function postAjax(opts, data) {
  34. $.Deferred(function(){});
  35. return new Promise(function(resolve, reject) {
  36. $.ajax({
  37. url: opts.http + opts.url,
  38. type: opts.type,
  39. dataType: "JSON",
  40. contentType: 'application/json; charset=UTF-8',
  41. data: JSON.stringify(data),
  42. headers: {
  43. "Authorization": opts.tok
  44. },
  45. error: function() {
  46. localStorage.removeItem("AjaxGen");
  47. localStorage.removeItem("ylToken");
  48. top.location.href = "../index.html";
  49. },
  50. success: function(dart) {
  51. if(dart.code == 401||dart.status == -1){
  52. localStorage.removeItem("AjaxGen");
  53. localStorage.removeItem("ylToken");
  54. top.location.href = "../index.html";
  55. }else{
  56. resolve(dart);
  57. }
  58. }
  59. });
  60. })
  61. }