使用fetch轻松解决JS跨域请求问题——无需CORS,jsonp

fetch(url, {
        method: "POST",
  mode: "no-cors",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  body: "请求参数"
        }).then(function(res) {
 console.log("Response succeeded?", JSON.stringify(res.ok));
 console.log(JSON.stringify(res));
}).catch(function(e) {
 console.log("fetch fail", JSON.stringify(params));
});

你可能感兴趣的:(前端,跨域,javascript,fetch)