PIPIONE
第一选择JSONP,如果不能使用需要检查是否是http/https的原因,需要注入网站和jsonp地址都是http或者https.更复杂的逻辑可以选择下面的:需要前后台都加以配合,并且https|http保持一致:前端:function ajax(url,data) { var request = new XMLHttpRequest(); request.addEventListener("load", function () { if (request.status == 200) { //请求成功,处理业务 } else { if (opts.error) { //请求失败了 } } }, false); request.addEventListener("error", function () { console.log('出错了'); }, false); request.addEventListener("abort", function () { console.log('中断了'); }, false); request.open("POST"), url, true); request.setRequestHeader("X-Requested-With", "XMLHttpRequest"); var fromData = new FormData(); for (var k in data) { fromData.append(k, opts.data[k]); } request.send(fromData); }后端,PHP为例: header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); //具体业务逻辑如果你当前的网页是http的,那么被请求的http也应该是http,反之https也是一样的