반응형
jQuery POST 양식 데이터
내가 submit을 클릭하면 모든 양식 데이터를 process.php로 게시했으면 합니다.그럼 진행 중입니다.php POST 데이터를 반향하고 마지막으로 결과 div의 모든 것을 프로세스에서 수행된 것으로 대체하고 싶습니다.php.
<script type="text/javascript">
$(document).ready(function(){
$("#myform").submit( function () {
$.ajax({
type: "POST",
dataType: "html",
cache: false,
url: "process.php",
success: function(data){
$("#results").html(data);
}
});
return false;
});
//$("#myform").submit( function () {
//$('#results').html("yay");
//}
// });
//} );
});
</script>
<form name="myform" id="myform" action="" method="POST">
<!-- The Name form field -->
<label for="name" id="name_label">zoom</label>
<input type="text" name="zoom" id="zoom" size="30" value=""/>
<br>
</select>
<!-- The Submit button -->
<input type="submit" name="submit" value="Submit">
</form>
<!-- FORM END ---------------------------------------- -->
<!-- RESULTS START ---------------------------------------- -->
<div id="results">nooooooo<?PHP $_SESSION[''] ?><div>
<!-- <input type="image" name="mapcoords" border="0" src="mapgen.php"> ---- -->
<!-- RESULTS END ---------------------------------------- -->
전화하셔도 됩니다.$.post양식 데이터를 직렬로 전달합니다.다음과 같이:
<script type="text/javascript">
$(document).ready(function(){
$("#myform").submit( function () {
$.post(
'process.php',
$(this).serialize(),
function(data){
$("#results").html(data)
}
);
return false;
});
});
</script>
$("#myform").submit( function () {
$.ajax({
type: "POST",
data : $(this).serialize(),
url: "process.php",
success: function(data){
$("#results").html(data);
}
});
return false;
});
테스트해보세요
그 모든 것을 할 수 있는 다른 방법이 있을 뿐입니다.이 예제에서는 jQuery validate 플러그인을 사용합니다.여기서 모든 양식 필드는 자동으로 유효성 검사됩니다.여기서 jquery 다운로드:
https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js
여기서 유효성 검사 플러그인 다운로드:
http://jquery.bassistance.de/validate/jquery-validation-1.10.0.zip
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jquery.validate.1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#customForm").validate({
debug: false,
rules: {
name: {required:true,minlength:8,maxlength:8},
email: {required:true,email:true},
},
submitHandler: function(form) {
// do other stuff for a valid form
$('#rsltx').html('<img src="WhiteLoading.gif"> Processing... please wait');
$.post('post.php', $("#customForm").serialize(), function(data) {
$('#rsltx').html(data);
});
}
});
});
</script>
<form method="post" id="customForm" action="">
<div>
<label for="name">Name</label>
<input id="name" name="name" type="text" autocomplete="off" required/>
</div>
<div>
<label for="email">E-mail</label>
<input id="email" name="email" type="email" autocomplete="off" required/>
</div>
<div>
<input id="send" name="send" type="submit" value="Send" />
</div>
</form>
var form = $('#mob_ticket_form')[0];
var data = new FormData(form);
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: '{{route("submit_ticket")}}',
data: data,
processData: false,
contentType: false,
cache: false,
timeout: 800000,
success: function(response) {
if (response.status == 200) {
$("#exampleModalCenter").modal('show');
} else {
alert(response.message);
}
},
error: function(response) {
// console.log(response)
notify('Something went Wrong!', 'danger')
}
});
언급URL : https://stackoverflow.com/questions/5772839/jquery-post-form-data
반응형
'programing' 카테고리의 다른 글
| jQuery에서 이벤트 핸들러에 인수를 전달하려면 어떻게 해야 합니까? (0) | 2023.09.12 |
|---|---|
| %wt% 등이 작동하지 않음 (0) | 2023.09.12 |
| k8s 작업을 통해 데이터베이스 마이그레이션 실행 (0) | 2023.09.12 |
| PHP의 Strict 모드 (0) | 2023.09.12 |
| 정적 메서드가 아닌 메서드를 정적으로 호출하면 안 됩니다. (0) | 2023.09.12 |