代码如下
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'];
$arr = array('a'=>"tt", 'b'=>"tt2", 'c'=>"tt3");
print_r($arr);
?>
运行后得不到php里的数组,求大侠讲解一下,最好贴出修改后的代码
要返回json字符串或json对象,php有自带的函数,echo json_encode($arr)
先确定print_r(arr)输出的是:{"a":"tt","b:""tt2","c":"tt3"}