Your checkbox names should have []
appened to them, i.e.,
<input type="checkbox" name="check[]" value="value1" />
This is a PHP-specific thing that lets PHP know it should interpret the POST data as an array.
Secondly, you don't need to parse the data on the PHP side. PHP does that for you automatically. $_POST['str']
is not valid -- you haven't sent any inputs with the name "str". PHP has no idea what your JavaScript variable names are.
var_dump($_POST)
instead and see what it contains. That should point you in the right direction.
Your JavaScript is wrong too:
function ajaxjquery(){
var str = $("#form1").serialize();
$.ajax({
type: "POST",
url: "test.php",
data: str
})
.done(alert(str)); // alert() will be called immediately, you need to put this in a closure like so:
.done(function(response) { alert(response); });
$.get("test.php", function(data) {
alert("Response: " + data);
}); // this is sending a separate GET request to test.php passing no data to it -- PHP will never receive any POST nor GET variables
}