前端
<!--PHP编程实战-->
<!--JSON & Ajax -->
<!--15-15-->
<!--使用$.getJSON和.each-->
<html>
<head>
<title>Loading JSON with jQuery</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.getJSON("json_example.php", function (data) {
$.each(data, function (continent, animals) {
var message = "<strong>" + continent + "</strong></br>";
for (j = 0; j < animals.length; ++j) {
message += animals[j] + ", ";
}
// remove last comma and space
message = message.trim();
message = message.substring(0, message.length - 1);
$("#generated_content").append("<p>" + message + "</p>");
})
})
}
)
</script>
</head>
<body>
<p><strong>Ajax parsed XML:</strong></p>
<div id="generated_content"> </div>
</body>
</html>
服务器端json_example.php返回json字符串
<?php
$animals = array(
"africa" => array("gorilla", "giraffe", "elephant"),
"asia" => array("panda"),
"north america" => array("grizzly bear", "lynx", "orca"),
);
print json_encode($animals);
?>
重点
问题
js不同函数回调函数的几种形式是在哪里定义好的?