求教一道关于jquery里$.post()函数与php数组之间数据传递的问题?
代码如下
A.html
<!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=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jQuery.js"></script>
<script>
$(function () {
$.post("cx2.php", {name:'cx', number:'1'}, function(data){
alert(data.a);
}, "json");
})
</script>
</head>
<body>
<h2>hhhhh</h2>
</body>
</html>
——————————
cx2.php
<?php
$name = $_POST['name'];
$number = $_POST['number'];
var arr = array('a'=>"tt", 'b'=>"tt2", 'c'=>"tt3");
print_r(arr);
?>
运行后得不到php里的数组,求大侠讲解一下,最好贴出修改后的代码
------解决方案--------------------
cx2.php 下面这样写
PHP code
$arr = array('a'=>"tt", 'b'=>"tt2", 'c'=>"tt3");
echo json_encode($arr);