您的位置:首頁技術文章
文章詳情頁

javascript - ajax請求nodejs后臺,開啟服務器后,localhost:3000/index.html頁面既沒有報錯,也沒有文字。。。

瀏覽:73日期:2023-09-09 11:48:06

問題描述

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/...

標簽: JavaScript
国产综合久久一区二区三区