HTML:
<html>
<head>
<title>AJAX</title>
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<script src="testing.js" type="text/javascript"></script>
<script src="http://www.json.org/json2.js"></script>
</head>
<body>
<input type="button" value="btnText" id="btntext" />
<input type="button" value="btnJSON" id="btnjson" />
</body>
</html>
PHP:
<?
header('Content-type: application/json');
echo '{"id": 1, "name": "abc", "email": "me123@aol.com"}';
?>
JS:
$(document).ready (function () {
$("#btntext").click(function () {
$.get("testing.text", function (data) {
alert(data);
});
});
$("#btnjson").click(function () {
$.get("testing.php", function (data) {
alert(data);
});
});
});
单击文本按钮时,警报可以正常工作。单击 json 按钮时,警报显示 'header('Content-type: application/json'); echo '{"id": 1, "name": "abc", "email": "me123@aol.com"}'
我的问题是,如果我单击 json 按钮,我怎样才能只提醒电子邮件显示“me123@aol.com”?