chengxiao35

jQuery的Ajax写法

1、什么是Ajax :是与服务器交换数据的技术,在不重载全部页面的情况下,实现了对部分网页的更新

2、jQuery的Ajax写法

    <script src=".............."></script>

  (1)$.ajax({

       //请求的地址

       url:“。。。。。。。。。。。。。。。。。。。。”,

       //请求的方式

       type:"get"   或者“post”

       //请求的参数

       data:{},

       //在成功发送请求之前

                         beforeSend: function (){函数}

       //成功回调

       success:function(res){

          console.log(res)

        },

       //回调失败

        error{

          console.log(404)

        }

        //成功发送请求后

                         complete: function(){函数}

      })

    (2)     $.post(\'https://showme.myhope365.com/api/shop/shopGoods/open/hot/list\', { pageSize: 1, pageNum: 3 }, function (res) { console.log(res) }) 

 

    (3)     $.get(\'https://showme.myhope365.com/api/shop/shopGoods/open/banner/list\',{},function(res){console.log(res)})

     </script>

 

    (4)   元素.load()  可以将本地的内容加入到html中

     $(function () {
            $(\'#btn1\').click(function () {
                // jquery中提供了一个load方法,功能:把请求回来的数据添加到指定的容器中
                $(\'#box\').load(\'02.案例.html\', function (responseTxt, statusTxt, xhr) {
                    console.log(responseTxt);       //请求回来的内容
                    console.log(statusTxt);      //请求的状态 success   error
                    console.log(xhr)           //ajax的实例对象
                })

            })
        })

分类:

技术点:

相关文章: