Loading

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>
posted @ 2022-05-19 16:37  _JunJun  阅读(73)  评论(0)    收藏  举报