1.js代码
开启服务器访问这个html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
// 定义一个函数,作为另一个函数的参数,但满足一定条件时由其他函数调用
// 这里的f,就被称为回调函数
var f = function(){
console.debug("回调方法,被调用!");
}
setTimeout(f,3800);
$.ajax({
type: "POST", // 请求类型
url: "ajax.json", // 请求路径
success: function(result){
console.debug(result.msg);
},
error:function(result){
console.debug(result.msg);
}
});
</script>
</head>
<body>
</body>
</html>
2.ajax代码
{
"msg":"请求失败",
"code":400
}