zoukankan      html  css  js  c++  java
  • ajax的三次封装简单概况

        原生ajax:
                    readyState         准备状态
                    status             页面状态
                    send            发送请求
                    open            打开对象,设置请求
                    XMLHttpRequest    火狐 谷歌 等浏览器适用
                    ActiveXObject    IE适用
                     
                   ajax第一次封装 (内容顺序不唯一)
                         $.ajax({
                             url:"",//路径
                             data:{},//传递的参数
                             type:"",//提交方式post/get
                             dataType:"",//预期服务器返回的数据类型json/text
                             success:function (){},//成功时的回调函数
                             error:function (){},//失败时的回调函数
                             async: true/false 是否异步
                         });
                         
                       ajax第二次封装   (内容顺序唯一)
                        $.post(
                            "",//url路径
                            {},//data传递的参数
                            function(){},//成功时的回调函数success
                            "" //第一次封装dataType => 第二次封装type 预期服务服务器返回的数据类型 json/text
                        )


                        $.get(
                            "",//url路径
                            {},//data传递的参数
                            function(){},//成功时的回调函数success
                            "" //第一次封装dataType => 第二次封装type 预期服务服务器返回的数据类型 json/text
                        )


                         $("#div1").load(//括号中是对象
                            "",//规定要将请求发送到哪个 URL。
                            {data},//可选。规定连同请求发送到服务器的数据。
                            function(responseTxt,statusTxt,xhr){//可选。规定当请求完成时运行的函数。
                             //response - 包含来自请求的结果数据
                             //status - 包含请求的状态("success", "notmodified", "error", "timeout" 或 "parsererror")
                             //xhr - 包含 XMLHttpRequest 对象
                                if(statusTxt=="success")
                                    alert("加载成功!");
                                if(statusTxt=="error")
                                    alert("Error: "+xhr.status+": "+xhr.statusText);
                        });


                       ajax第三次封装
                        $.getJSON(//只接收json类型的数据
                            "",//url 路径
                            {},//data 传递的数据
                            function (){//success成功时的回调函数
                                
                            }
                        );


                        $.getScript(
                            "http://localhost:8080/demo.js",//url路径(可以是不同的项目中)
                            function (){//success成功时的回调函数
                                alert("成功的执行了js文件,划拉");
                            }
                        );

  • 相关阅读:
    D-Bus,kdbus和Binder
    Android init system replaced with systemd & binder replaced by kdbus
    在 Android 上 chroot 一个 ArchLinux
    An experiment in porting the Android init system to GNU/Linux
    Android init
    Linux和RISC-V基金会宣合作,打造开源CPU!
    How does systemd use /etc/init.d scripts?
    SysV, Upstart and systemd init script coexistence
    Purism Shows Off Latest GNOME Mobile Shell Mockups For The Librem 5
    One Widget to Adapt Them All and to The Librem 5 Port Them
  • 原文地址:https://www.cnblogs.com/Dylan_G/p/10632568.html
Copyright © 2011-2022 走看看