1.html文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
// 方法一
// $.ajax({
// "url":"data.json",
// "type":"GET",
// "dataType":"JSON",
// success:function(data){
// alert(data.name)
// },
// error:function(){
// alert("error")
// },
// async:true
// });
// 方法二
// 1.请求的地址
// 2.请求传给web服务器的参数
// 3.请求成功的回调函数
// 4.返回数据的解析方式
// 5.error失败执行的回调函数
// $.get("data.json",{"name":"ls"},function(data){
// console.log(data.name)
// },"JSON").error(function(){
// alert("失败")
// });
// post请求
$.post("data.json",{"name":"ls"},function(data){
console.log(data.name)
},"JSON").error(function(){
alert("失败")
});
</script>
</head>
<body>
</body>
</html>
2.data.json
{"name": "bob"}
3.run http server:
https://blog.csdn.net/CherryChanccc/article/details/135834540?spm=1001.2014.3001.5502
4.