我直接从w3学校示例中获取此代码,但是,在“Tryit编辑器”之外,它不适用于我。有任何想法吗?jQuery AJAX getJSON()方法示例不适用于我
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$.getJSON("http://w3schools.com/jquery/demo_ajax_json.js", function (result) {
$.each(result, function (i, field) {
$("div").append(field + " ");
});
});
});
});
</script>
</head>
<body>
<button>Get JSON data</button>
<div></div>
</body>
</html>
跨域限制,以取代
jquery/demo_ajax_json.js
与your file name.js
即
$.getJSON("http://w3schools.com/jquery/demo_ajax_json.js", function (result)
? – fmgp 2012-04-21 20:34:23此外,[避免使用w3schools](http://w3fools.com/)将是一个好主意。 – rid 2012-04-21 20:34:57
http://www.ibm.com/developerworks/library/wa-aj-jsonp1/ – 2012-04-21 20:35:28