<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-1.12.4.min.js"></script>
<script>
$(function () {
$.ajax({
url: "test.json",
type: "get",
dataType: "json",
data: {name: "abc"},
success: function (response) {
alert(response.name)
},
error: function () {
alert("错误")
},
async: true
})
})
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-1.12.4.min.js"></script>
<script>
$(function () {
$.post("test.json", {name: "abc"}, function (response) {
alert(response.name)
}, "json").error(function () {
alert("错误")
})
})
</script>
</head>
<body>
</body>
</html>
//test.json { "name": "张三", "age": 20 }