Ajax
jQuery的Ajax请求
- $.get.post(url,data,callback)
- $.ajax(type:'',url:'',data:{},success:function(){})
点击查看代码
<!DOCTYPE html>
<html>
<head>
<title>学习$.get(url,[data],[callback]</title>
<meta charset="utf8">
<script src="./js/jQuery.min.js">
</script>
<script>
$(function () {
$('#b1').click(function () {
$.get('http://www.liulongbin.top:3006/api/getbooks', function (res) {
console.log(res)
})
})
$('#b2').click(function () {
$.get('http://www.liulongbin.top:3006/api/getbooks', {"id":"2"},function (res) {
console.log(res)
})
})
$('#b3').click(function () {
$.post('http://www.liulongbin.top:3006/api/addbook', {bookname: "测试测试a", author: "fdsf", publisher: "bjtsg"},function (res) {
console.log(res)
})
})
$('#b4').click(function () {
$.ajax({
type:'POST',
url:'http://www.liulongbin.top:3006/api/addbook',
data:{bookname: "测试测试b", author: "fdsf", publisher: "bjtsg"},
success:function(res){
console.log(res)
}
})
})
})
</script>
</head>
<body>
<button id="b1">测试不带参数的$.get</button>
<button id="b2">测试带参数的$.get</button>
<button id="b3">测试$.post</button>
<button id="b4">测试$.ajax</button>
</body>
</html>
本文来自博客园,作者:_JunJun,转载请注明原文链接:https://www.cnblogs.com/--ah/p/16289100.html

浙公网安备 33010602011771号