response.writeHead(200, { "Content-Type": 'text/plain', 'charset': 'utf-8', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS' });//可以解决跨域的请求
例如
function onRequest(request, response) {
response.writeHead(200, { "Content-Type": 'text/plain', 'charset': 'utf-8', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS' });//可以解决跨域的请求
var str = 'Hello World!';
console.log(str);
response.write(str);
response.end();
}
本文介绍了一种通过设置HTTP响应头来解决跨域请求问题的方法,包括Content-Type、charset、Access-Control-Allow-Origin和Access-Control-Allow-Methods等关键字段的使用。
8918

被折叠的 条评论
为什么被折叠?



