<html>
<form class="Headerformsearch" action="http://localhost:8080/" method="GET">
<div class = "SearchItem">
<div class="input-group">
<input type="text" class="formcontrol" aria-label="..." placeholder="Search for products,brands and more">
</div>
</div>
<div class = 'searchicon'>
<button id = "search" type = 'submit'>
<i class="glyphicon glyphicon-search"></i>
</button>
</div>
</form>
<style>
.formcontrol{
width:500px;
height: 35px;
border-radius: 2px;
border-color: blue;
}
.input-group, .searchicon{
display: block;
float: left;
}
#search{
width:50px;
height: 36px;
background-color: white;
}
</style>
</html>
在上面的代码段中,我试图使用HTML标记形式从本地主机服务器获得响应,如果在搜索框中输入``watches'',则应该以``watch''字符串形式获得响应。我不知道将数据附加到URL。 这是如何工作的,我该如何实现?
服务器端程序:
var http = require('http');
var fs = require('fs');
var url = require('url');
//var adr = "http://localhost:8080/?watches"
http.createServer(function (req, res) {
adr = url.parse(req.url, true);
var query = url.parse(adr, true);
var search = (query.search).replace('?', '');
switch(search){
case 'watches': res.end('Watch');
default : res.end('No information available in the server');
}
}).listen(8080);
在上面的服务器端代码中,我试图监听8080并处理URL并根据URL内容发送响应。在URL栏中尝试时效果很好。但是我想从表单HTML标签