javascript - ajax请求nodejs后台,开启服务器后,localhost:3000/index.html页面既没有报错,也没有文字。。。
问题描述
index.html的代码为(页面上有两个输入框和一个按钮):
$('input[type=button]').on('click',function() {if ( $username=='' || $password=='' ) { alert('请输入完整!');} else { $.ajax({type: 'POST',url: 'http://localhost:3000',data: { user: $username, pwd: $password},success: function(data) { var data=JSON.parse(data); console.log(data);},error: function() { alert('出错啦!');} })} })
server.js的代码是:
var http=require(’http’);var querystring=require(’querystring’);http.createServer(function(req, res) { var data=''; req.on('data', function(chunk) {data+=chunk; }) req.on('end', function() {data=querystring.stringify(data);res.end(data); })}).listen(3000, function() { console.log('Starting to listen on port 3000');})
启动服务器后,页面上啥都没有,一篇空白。。。扎心了
问题解答
回答1:你的server端的信息写错了
理解一下webserver的原理
你看一下这个简单的例子,看看知不知道怎么改https://github.com/cristicmf/...
