将vars从js传递到节点
我有一个按钮,按下时我想让它从该js文件发送一个对象(日志)数组到一个节点js文件,然后我可以输出一个JSON文件。我已经尝试了与this tutorial and this one的AJAX,但我仍然不明白如何在js和节点之间传递变量。
const done_but = document.getElementById("done");
var logs = []
var xhttp = new XMLHttpRequest();
document.getElementById('r2').checked = true;
done_but.onclick = function() {
const student = document.getElementById("student-drop").value;
const face = document.querySelector('input[name="faceses"]:checked').value;
const time = new Date();
logs.push([{
student: student,
face: face,
time: time.toUTCString()
}]);
xhttp.open("POST", "file:///(file path)/index.html");
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
xhttp.send(logs);
console.log(logs);
};
回答如下:
我发现如果你把你的样式和本地js放到你的HTML文件中,你可以把它写到屏幕然后从本地js获取任何输入。要提供服务器数据
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "http://localhost:8000");
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
xhttp.send(YourVar);
与本文相关的文章
评论列表(0)
- 暂无评论