Im just new in using ajax and I was following a tutorial from this link http://ricochen.wordpress.com/2011/08/02/passing-array-of-checkbox-values-to-php-through-jquery-example/
But i wasnt able to make it work can you pls help me on this?
html code :
<html>
<head>
<script src="jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function doit() {
var p=[];
$('input.cb').each( function() {
if($(this).attr('checked')) {
p.push($(this).attr('rel'));
}
} );
$.ajax( {
url:'/test2.php',
type:'POST',
data: {list:p},
success: function(res) {
alert(res);
}
});
}
</script>
</head>
<body>
<input type="checkbox" class="cb" rel="1"></input>This is 1<br />
<input type="checkbox" class="cb" rel="abc"></input>This is abc<br />
<input type="checkbox" class="cb" rel="999"></input>This is 999<br />
<a href="javascript:void(0)" onclick="doit()">Click</a>
</body>
</html>
test2.php :
<?php
print_r(@$_POST['list']);
?>