node.js를 사용하고 표현합니다. 버튼 (btnSend)을 누르면 express (페이지를 새로 고치지 않고)로 node.js로 데이터를 보내려고합니다. 데이터를 보내려면 어떻게해야합니까? jquery 사용하기?Node.js - 양식 제출
도와주세요.
감사합니다.
$("form").submit(function(e) {
e.preventDefault(); // Prevents the page from refreshing
var $this = $(this); // `this` refers to the current form element
$.post(
$this.attr("action"), // Gets the URL to sent the post to
$this.serialize(), // Serializes form data in standard format
function(data) { /** code to handle response **/ },
"json" // The format the response should be in
);
});
이 코드는 페이지의 모든 폼 요소를 발견하고 그들로부터 제출 이벤트를 수신
<form action="/Send" method="post">
Username:
<input type="text" name="user" id="txtUser" />
<input type="submit" value="Submit" id="btnSend" />
</form>
이 주제는 아니지만 "사용자 이름 :"및 텍스트 입력 요소를 [레이블 태그] (https://developer.mozilla.org/en/HTML/Element/label)로 묶는 것을 고려하십시오. 양식을 좀 더 의미 있고 사용하기 쉽도록 만듭니다. – Xavi