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>
How do i process (or read) multiple checked checkbox's value in PHP? I tried doing $_POST['content'] to grab the serialized data but no luck.
$_POST['opts'](it will return an array). If you need to keep it as json, tryvar_dump($_POST)to see what you're getting.dataTypeparameter indicates the server response content type, not the request.data:{ content: content }lineapplication/x-www-form-urlencodedrequest. Nothing to do with JSON. If you wanted to send JSON to the server you would specify thecontentType: 'json'and you would JSON serialize the request:data: JSON.stringify({ content: 'some content' }).