当我单击按钮时,可以从节点服务器以(req.body.PDF)形式接收数据。当我打开HTML文件而不单击按钮时,我想使(req.body.PDF)在服务器上可用。我该怎么办???
我希望数据无需单击按钮即可直接发送到服务器。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="../style/tablesheets.css">
</head>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<!-- jquery-->
<script>
var html = "";//1.
$(document).ready(() => {//start
init();
});
init = () => {
$.ajax({
type: "post",
dataType: "json",
url: "http://localhost:3000/db/1",
success: (data) => {
$.each(data[0], (index, value) => {
// // console.log(data[0].Page1);
html += '<div id="testA">';
for (let index = 0; index < data[0].Page1.length; index++) {
html += '<div class = "first">';
html += '<h1>' + data[0].Page1[index].main +'</h1>';
html += '<h2>' + data[0].Page1[index].sub + '</h2>';
html += '<div>Action</div>';
html += '<div>' + data[0].Page1[index].act + '</div>';
html += '<div>Expected Result</div>';
html += '<div>' + data[0].Page1[index].expect + '</div>';
html += '<div>Result</div>';
html += '<div>' + data[0].Page1[index].is + '</div>';
html += '<div>Comment</div>';
html += '<div>' + data[0].Page1[index].text + '</div>';
html += '<div>' + data[0].Page1[index]._img + '</div>';
html += '<br>'
html += '</div>';
}
html += '</div>';
});
document.getElementById("PDF").value = html;//2. store
},
error: () => { // error
console.log('ajax error');
}
});
}
const SendTEST = () =>
{
document.getElementById('fristform').submit();
};
</script>
<body>
<div id = "testsubmit">
<form action="http://localhost:3000/pdfbox/" id="fristform" method='POST'><!--form -->
<input id='PDF' name='PDF' readonly>
<div onclick="SendTEST()">button</div>
</form>
</div>
</body>
</html>