http://www.tuicool.com/articles/7ve6ja
post跨域
var post = function (URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
history.go(-1)
};
var apiUrl = 'http://URL地址' + token + '&callback=?';
var content = $("#Content").val;
var contact = $("#Contact").val();
if (content != '' && contact != '') {
var params = {"content": content, "contact": contact};
// 直接调用post方法即可
post(apiUrl, params);
layer.msg('反馈成功');
}
get方式跨域
var fetchUrl = '带http的url地址' + token + '&callback=?';
$.getJSON(fetchUrl + '', function (res) {
console.log(res);
});