var genUrl = "http://39.98.35.167:9999"; var baseUrl = "http://121.37.6.200:8088"; // GET请求 function getAjax(opts, data) { $.Deferred(function(){}); return new Promise(function(resolve, reject) { $.ajax({ url: opts.http + opts.url, type: opts.type, dataType: "json", data: data, headers: { "Authorization": opts.tok }, error: function() { localStorage.removeItem("AjaxGen"); localStorage.removeItem("ylToken"); top.location.href = "../index.html"; }, success: function(dart) { if(dart.code == 401||dart.status == -1){ localStorage.removeItem("AjaxGen"); localStorage.removeItem("ylToken"); top.location.href = "../index.html"; }else{ resolve(dart); } } }); }) } // POST请求 function postAjax(opts, data) { $.Deferred(function(){}); return new Promise(function(resolve, reject) { $.ajax({ url: opts.http + opts.url, type: opts.type, dataType: "JSON", contentType: 'application/json; charset=UTF-8', data: JSON.stringify(data), headers: { "Authorization": opts.tok }, error: function() { localStorage.removeItem("AjaxGen"); localStorage.removeItem("ylToken"); top.location.href = "../index.html"; }, success: function(dart) { if(dart.code == 401||dart.status == -1){ localStorage.removeItem("AjaxGen"); localStorage.removeItem("ylToken"); top.location.href = "../index.html"; }else{ resolve(dart); } } }); }) }