下載phpstudy搭建本機伺服器
#data.json如下
{
name:"lvyuanyaun",
age:"25"
}
hello.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
</head>
<body>
<button id="btn">点击</button>
<h5 id="text">....</h5>
<script src="jq.js"></script>
<script type="text/javascript">
$("#btn").click(function() {
$.ajax({
type: "GET",
url: "data.json",
dataType: "json",
success:function(data) {
console.log(data)
}
});
})
</script>
</body>
</html>
network顯示data.json已被載入
##console.log(data)什麼都沒顯示
把url那個參數改成有http的訪問位址試試