服务端代码是:
var http=require('http');
var querystring=require('querystring');
var util=require('util');
http.createServer(function(req, res) {
var postData = "";
req.on("data", function (data) {
postData += data;
});
req.on("end", function () {
post = querystring.parse(postData);
res.write(post);
res.end();
});
}).listen(3000, function() {
console.log("Starting to listen on port 3000");
})
ajax的代码是:
$.ajax({
type: "POST",
url: "http://localhost:3000",
dataType:"jsonp",
data: {
user: $username,
pwd: $password
},
success: function(data) {
var data=JSON.parse(data);
console.log(data);
},
error: function() {
alert("出错啦!");
}
})
ajax发送的是两个表单数据,打开localhost:3000/index.html是空白的,输入框都没有,控制台也没有,也不报错。。。