jQuery的Ajax请求
一、jQuery的Ajax请求写法
//详细使用方法看下方代码实战部分
- ajax(url) //发起ajax请求
- get(url) //发起get请求
- post(url) //发起post请求
二、代码实战
代码的详细解读,可以参考视频教程
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="./res/jquery-1.11.3.min.js"></script>
</head>
<body>
<div id="myDiv">eeee</div>
<!-- 点击事件 -->
<button id="myBtn" onclick="doClick()">点击</button>
<script type="text/javascript">
function doClick(){
//ajax 请求
$.ajax({
url:'http://localhost:8080/hiajax',
success:function(data){
//alert(data)
$('#myDiv').html(data)
}
})
//get 请求
$.get('http://localhost:8080/hiajax', function (data,status) {
$('#myDiv').html(data)
})
//post 请求
$.post('http://localhost:8080/phiajax', function (data,status) {
$('#myDiv').html(data)
})
}
</script>
</body>
</html>