JQUERY :PHP에서 직렬화 JQuery와 데이터 읽기 (복수 체크 박스)
$(document).ready(function(){
$('form').submit(function(){
var content = $(this).serialize();
//alert(content);
$.ajax({
type: 'POST',
dataType: 'json',
url: 'http://localhost/test/generate',
timeout: 15000,
data:{ content: content },
success: function(data){
$('.box').html(data).fadeIn(1000);
},
error: function(){
$('.box').html('error').fadeIn(1000);
}
});
return false;
});
});
HTML :
<form>
<input type="checkbox" value="first" name="opts[]">
<input type="checkbox" value="second" name="opts[]">
<input type="checkbox" value="third" name="opts[]">
<input type="submit">
</form>
내가 어떻게 처리 할 (또는 읽기) 여러 PHP에서 체크 박스의 값을 확인? 나는 일련 번호가있는 데이터를 얻으려고했지만 행운은 누우려고 $_POST['content']
을 시도했다.
당신이 JSON으로 데이터를 전송해야 할 이유가 있습니까? 양식의 기본 게시물은 데이터를'$ _POST [ 'opts']'로 사용할 수있게합니다 (배열을 반환합니다). json으로 유지해야하는 경우'var_dump ($ _ POST)'를 사용해보십시오. – Grexis
그는 데이터를 JSON으로 보내지 않습니다. 'dataType' 매개 변수는 요청이 아닌 서버 응답 내용 유형을 나타냅니다. –
@Darin 아, jQuery에 대해 많이 다루지는 않았지만 (폼을 표시합니까? : D) 양식과 데이터 : {content : content} 행의 직렬화를 언급했습니다. – Grexis