반응형
jQuery - 비동기식으로 양식 보내기
다음과 같은 폼이 있습니다.
<form action='???' method='post' name='contact'>
<input type="text" class="inputContact" name="mittente" />
<textarea class="textContact" name="smex"></textarea>
<input type="submit" value="Send" />
</div>
</form>
이 데이터를 비동기적으로 전송하고 싶다.트러트 jQuery 함수$.ajax.
편집: 솔루션 사용:
<form name='contactForm'>
<input type="text" class="inputContact" name="mittente" />
<textarea class="textContact" name="smex"></textarea>
<input type="submit" value="Send" />
</form>
<script type="text/javascript">
$(document).ready(function() {
$('form[name=contactForm]').submit(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
cache: false,
url: './ajax/header_ajax.php',
data: 'id=header_contact_send&'+$(this).serialize(),
success: function(msg) {
$("#boxContentId").html(msg);
}
});
});
});
</script>
$('form[name=contact]').submit(function(){
// Maybe show a loading indicator...
$.post($(this).attr('action'), $(this).serialize(), function(res){
// Do something with the response `res`
console.log(res);
// Don't forget to hide the loading indicator!
});
return false; // prevent default action
});
참조:
언급URL : https://stackoverflow.com/questions/4985093/jquery-send-a-form-asynchronously
반응형
'programing' 카테고리의 다른 글
| @ExtendWith(SpringExtension.class)와 @ExtendWith(MockitoExtension.class)의 차이점은 무엇입니까? (0) | 2023.02.27 |
|---|---|
| angularjs를 사용하여 지연 후 값을 변경하는 방법은 무엇입니까? (0) | 2023.02.27 |
| 봄용 Tomcat 웹 서버에서 application.properties를 외부화하는 방법 (0) | 2023.02.27 |
| 레코드를 파기할 때 무엇을 렌더링해야 합니까? (0) | 2023.02.27 |
| Swift 4의 디코딩 프로토콜에서 사용자 지정 키를 사용하려면 어떻게 해야 합니까? (0) | 2023.02.27 |