function getData(opt){
var url = opt.url,
type = opt.type || "GET",
data = opt.data || {},
success = opt.callback || null;
if (type === 'POST') { // post请求跨域
var baseUrl = 'http://test.hccb.cc/publicManage';
$.ajax({
async: false,
type: type,
url: baseUrl + url,
headers: {
"Content-Type": "application/json;charset=utf8"
},
data: JSON.stringify(data),
dataType: 'json',
crossDomain: true,
success: function(data){
success && success(data);
},
fail: function(err){
console.log(err);
}
});
} else { // get请求跨域
$.ajax({
async: false,
type: type,
url: url,
data: data,
dataType: 'jsonp',
success: function(data){
if(data.message == 'false'){
window.location.href = data.data+"?url=";
} else {
success && success(data.data);
}
},
fail: function(err){
console.log(err);
}
});
}
}
网友评论