jqhttpsdk.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * 获取数据ajax-get请求
  3. * @author chanjunkai
  4. */
  5. // var http_ip_prot = 'http://192.168.136.40:4696/'
  6. let domain = document.domain;
  7. // let http_ip_prot = 'http://192.168.136.40:7724/';
  8. //生产环境
  9. // let http_ip_prot = 'http://47.107.129.126:7724/';
  10. var http_ip_prot = convertTemp()+ "/";
  11. if( http_ip_prot.indexOf("zositech")==-1 ){
  12. http_ip_prot="http://192.168.136.39:8000/";
  13. // http_ip_prot="http://www.zositech.xyz:7724/";
  14. console.log(http_ip_prot);
  15. }else{
  16. console.log(http_ip_prot);
  17. }
  18. // 获取访问路径
  19. function convertTemp(){
  20.    var the_url = document.location.toString();
  21.    var first_split = the_url.split("//");
  22.    var without_resource = first_split[1];
  23.    var second_split = without_resource.split("/");
  24.    var domain = second_split[0];
  25. return first_split[0] +'//'+ domain;
  26. }
  27. $.GetJSON = function (url, data, callback) {
  28. $.ajax({
  29. url: url,
  30. type: "get",
  31. contentType: "application/json",
  32. dataType: "json",
  33. timeout: 10000,
  34. data: data,
  35. success: function (data) {
  36. callback(data);
  37. }
  38. });
  39. };
  40. /**
  41. * 提交json数据的post请求
  42. * @author laixm
  43. */
  44. $.postJSON = function (url, data, callback) {
  45. $.ajax({
  46. url: url,
  47. type: "post",
  48. contentType: "application/json",
  49. dataType: "json",
  50. data: data,
  51. timeout: 60000,
  52. success: function (msg) {
  53. callback(msg);
  54. },
  55. error: function (xhr, textstatus, thrown) {
  56. }
  57. });
  58. };
  59. /**
  60. * 修改数据的ajax-put请求
  61. * @author laixm
  62. */
  63. $.putJSON = function (url, data, callback) {
  64. $.ajax({
  65. url: url,
  66. type: "put",
  67. contentType: "application/json",
  68. dataType: "json",
  69. data: data,
  70. timeout: 20000,
  71. success: function (msg) {
  72. callback(msg);
  73. },
  74. error: function (xhr, textstatus, thrown) {
  75. }
  76. });
  77. };
  78. /**
  79. * 删除数据的ajax-delete请求
  80. * @author laixm
  81. */
  82. $.deleteJSON = function (url, data, callback) {
  83. $.ajax({
  84. url: url,
  85. type: "delete",
  86. contentType: "application/json",
  87. dataType: "json",
  88. data: data,
  89. success: function (msg) {
  90. callback(msg);
  91. },
  92. error: function (xhr, textstatus, thrown) {
  93. }
  94. });
  95. };