传真:
<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": "[email protected]"} ;
?>
JS:
$(document).ready (function () {
$("#btntext").click(function () {
$.get("testing.text", function (data) {
alert(data);
});
});
$("#btnjson").click(function () {
$.get("testing.php", function (data) {
alert(data);
});
});
});
When clicking on the button for text, the alert works just fine. When clicking on the json button, the alert shows header( Content-type: application/json ); echo {"id": 1, "name": "abc", "email": "[email protected]"}
我的问题是,如果我点击了json,那么我如何能够仅仅提醒电子邮件,显示?