텍스트, 라디오 및 체크 박스 입력이있는 HTML 양식이 있습니다. AJAX로 제출할 때 배열의 마지막 체크 박스 값만 가져옵니다.PHP에서 AJAX로 체크 박스 값을 처리하지 못했습니다.
내 HTML 파일 :
<form class="ajaxonsubmit" action="process.php" method="post">
<label>Name</label><input type="text" name="name">
<label>Father's Name</label><input type="text" name="father_name">
<label>Gender</label>
<input type="radio" value="1" name="gender">Male <br>
<input type="radio" value="2" name="gender">Female <br>
<label>Options</label>
<select name="campus">
<option value="1">Option1 </option>
<option value="2">Option2 </option>
</select>
<label>Check List</label>
<input type="checkbox" name="check[]" value="1">
<input type="checkbox" name="check[]" value="2">
<input type="checkbox" name="check[]" value="3">
<button name="submit" type="submit">Submit</button>
내 JS 파일.
$('.ajaxonsubmit').on('submit', function() {
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(data) {
$("#wrap").html(data);
}
});
return false;
});
var_dump ($ _ POST)를 사용 중입니다. 배열을 검사하기 위해 process.php 함수를 사용하면 [ "check"] => array (1) {[0] => string (1) "3"}
에서 PHP 측
에 액세스 체크 [] 단순히 doesnot 배열에서 체크 박스 값을 저장 첨가 할 수있다. jquery를 사용하여 배열을 만들어야합니다. – user254153