node.js,版本
var app = require('express')();
var server = require('http').Server(app);
//运行跨域
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,XFILENAME,XFILECATEGORY,XFILESIZE,content-type,token,id,authorization");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1');
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
php版本
header("Access-Control-Allow-Origin:*"); /*星号表示所有的域都可以接受,*/
header("Access-Control-Allow-Headers:x-requested-with,content-type,Origin, X-Requested-With, Content-Type, Accept,XFILENAME,XFILECATEGORY,XFILESIZE,content-type,token,id,authorization");//添加头部请求的运行类型
header("Access-Control-Allow-Methods:PUT,POST,GET,DELETE,OPTIONS");
header("X-Powered-By:3.2.1");
header("Content-Type:application/json;charset=utf-8");