我遇到的问题是,当我按下提交按钮多次冻结时,我的应用程序只能提交一个1,一段时间后(大约1000.000毫秒),它会在控制台和玉页中返回最后一个请求。提交按钮从表单返回一个帖子并将其发送到同一页面。按钮的作用还有刷新页面。重要的是页面将(JSON)帖子返回到页面,并且还有另一个json请求将其发送到API(并将其返回到同一页面)
app.js
var options_search = {
hostname: 'host',
path: 'path',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': JSON request .length,
}
};
app.post('/result',function(req,response){
var keyword=req.body.user;
GLOBAL.objToJson ={ keyword };
response.write(JSON.stringify(GLOBAL.objToJson));
console.log("test " +JSON.stringify(GLOBAL.objToJson) );
});
app.get('/Search', function(req, res) {
var req = http.request(options_search, (resb) => {
var buffer_search = "";
resb.setEncoding('utf8');
resb.on('data', (chunks) => {
buffer_search += chunks;
});
resb.on('end', () => {
res.render('Search',{
title: 'Search',
value_search: buffer_search,
search_test: [JSON.stringify(GLOBAL.objToJson) ]
});
});
});
//res.redirect("/search");
req.write(search);
});
search.jade
doctype html
html
head
script(src='//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js')
script.
$(document).ready(function(){
var user,pass;
$("#submit").click(function(){
user=$("#user").val();
pass=$("#password").val();
$.post("http://localhost:3000/result",{user: user}, function(data){
if(data==='done')
{
alert("login success");
}
});
});
});
input#user(type='TEXT', size='40')
br
input#submit(type='button', value='Submit',onclick="location.href='search'")