3 回答
TA贡献1824条经验 获得超6个赞
require('http').createServer(function (req, res1) {
//res1.writeHead(200, {'Content-Type': 'text/plain'});
var request = require('./request');
request.request('login',
{
account: require('./params').account,
password: require('./params').password
}, function(res){
res1.writeHead(200, {'Content-Type': 'text/plain'});
res1.write( res.body );
res1.end();
});
}).listen(8080, "127.0.0.1");
TA贡献1829条经验 获得超13个赞
前端代码:
$(document).ready(function() {
$.ajax({
url: '127.0.0.1:1337', //不知道这个url到底应该填什么
dataType: "jsonp",
data: '{"data": "TEST"}',
type: 'POST',
jsonpCallback: 'callback',
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret.msg)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
});
后端代码:
var http = require('http');
var util = require('util')
http.createServer(function (req, res) {
console.log('Request received: ');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.on('data', function (chunk) {
console.log('GOT DATA!');
console.log(data);
});
res.end('callback(\'{\"msg\": \"OK\"}\')');
}).listen(1337,'127.0.0.1');
console.log('Server running on port ');
- 3 回答
- 0 关注
- 1890 浏览
添加回答
举报