I try to pass array using jquery by ajax and back but my code not working well. I all the time change it but it is not working. please advise what to do. I think my jquery code is ok but php code not replay. thx.
html code.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
var allVals = {
'a': '1',
'b': '2',
'c': '3'
};
//$.each(allVals, function(key, value) {
//alert(key + ': ' + value);
// });
});
$.ajax({
type: "POST",
dataType: 'html',
url: "test4.php",
data: 'allVals=' + allVals,
cache: false,
success: function(data)
{
alert(data);
$('#test').html(data);
}
});
</script>
<title>Insert title here</title>
</head>
<body>
<div id="test">##</div>
</body>
</html>
php code test4.php
<?php
$allVals = $_POST['allVals'];
if ($allVals != ""){
foreach ($allVals as $key => $value) {
echo ($key.' '.$value."<br />");
} }
?>
data: 'allVals=' + allVals,
– ianace Jun 5 at 7:38