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. – Grexis Jan 6 '12 at 8:11dataType
parameter indicates the server response content type, not the request. – Darin Dimitrov Jan 6 '12 at 8:13data:{ content: content }
line – Grexis Jan 6 '12 at 8:17application/x-www-form-urlencoded
request. 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' })
. – Darin Dimitrov Jan 6 '12 at 8:19