이것은 내 JavaScript 함수입니다. Google에서이 함수를 얻습니다.POST의 값 전달 방법 JavaScript를 사용하는 방법
function postURL() {
var jobValue = document.getElementsByName('folderName')[0].value;
url = 'http://localhost:8888/TaaS/Sachin/Input' + "?FolderName=" + jobValue;
var form = document.createElement("FORM");
form.method = "POST";
//if(multipart) {
form.enctype = "multipart/form-data";
//}
form.style.display = "none";
document.body.appendChild(form);
form.action = url.replace(/\?(.*)/, function(_, urlArgs) {
urlArgs.replace(/\+/g, " ").replace(/([^&=]+)=([^&=]*)/g, function(input, key, value) {
input = document.createElement("INPUT");
input.type = "hidden";
input.name = decodeURIComponent(key);
input.value = decodeURIComponent(value);
form.appendChild(input);
});
return "";
});
form.submit();
}
나는이 함수를 onclick 중에 호출한다.
<button type="submit" class="btn btn-primary start" onclick="postURL()">
<i class="glyphicon glyphicon-upload"></i>
<span>Create Folder</span>
</button>
내 서버 쪽에서 node.js를 사용하고 있습니다. 서버 측의 버튼 클릭 이벤트 중에 POST 메서드가 호출되지만 POST 메서드 중 node.js 파일에서 "jobValue"를 검색하는 방법을 알지 못합니다.
POST 방법 :
function(req, res) {
switch (req.method) {
case 'OPTIONS':
res.end();
break;
case 'POST':
console.log('req.url: ' + req.url);
break;
default:
res.statusCode = 405;
res.end();
}
}
어떻게 Node.js를 파일에서 해당 값을 얻을?
입력 ID를 넣고 사용하십시오. document.getElementById ('id'); – CodeSlayer
node.js 파일에서 해당 값을 가져 오는 방법은 무엇입니까? – thevan