实现跨域请求ajax封装
2018-08-03 本文已影响0人
smallBear
<script src="jquery.js"></script>
var baseUrl=""
if(document.domain=="localhost"){
baseUrl="http://"+document.domain+":8650"
}else{
baseUrl="https://"+document.domain;
}
function get(url,callback,data) {
.ajax({ type: "GET", url: baseUrl+"/"+url, data: data, dataType: "json", success: function (data) { callback(data) } }); } function post(url,callback,data) {.ajax({
type: "post",
url: baseUrl+"/"+url,
data: data,
dataType: "json",
success: function (data) {
callback(data)
}
});
}