var qs = require('querystring');
var http = require('http');
var server = http.createServer();
server.on('request', function (req, res) {
var params = qs.parse(req.url.split('?')[1]);
console.log(params)
var fn = params.callback;
// jsonp返回设置
res.writeHead(200, {
'Content-Type': 'text/javascript'
});
res.end(fn + '(' + JSON.stringify(params) + ')');
});
server.listen('8080');
console.log('Server is running at port 8080...');
前端代码
node 代码