node.js - nodejs中单击事件的Ajax调用问题
问题描述
我需要知道在 nodejs 中使用 ajax。我在我的 nodejs 应用程序中使用此代码
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
}
};
xhttp.open("POST", "/test1", true);
xhttp.send();
问题是它在点击事件中只被调用了 6 次。第 7 次和第 8 次速度很慢,依此类推。它适用于页面刷新,但不适用于点击事件。
我的服务器端代码:-
router.post('/test1', function(req, res){
console.log("TEST1");
});
解决方案
尝试将某些内容作为响应返回给客户端:
res.send('');
或者,您可以使用next()
将控制权发送回客户端:
router.post('/test1', function(req, res, next){
console.log("TEST1"); next();
});
推荐阅读
- javascript - 正在努力运行 Storybook
- excel - 如何计算一列对多列的所有组合
- python - 从 Python 2.7 中的 csv 文件中剥离最后一行/页脚
- vue.js - Vuetify - 制作带有居中文本的方形 v-card(两个轴)
- swift - NSKeyedUnarchiver.unarchiveTopLevelObjectWithData 返回 nil
- python - 安装 pywin32 时出错(在 Ubuntu 上)
- php - 如何从订单详细信息页面中删除产品链接?
- python - 如何比较两个 pandas 数据框并返回将它们相互映射的索引?
- html - 通过使用带有 CSS3 的变换自动缩放内容以匹配其包装器的区域
- amazon-web-services - AWS dynamoDB - 如何在创建项目时显示新属性(未在创建表时创建)