zoukankan      html  css  js  c++  java
  • jquery的ajax

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     2 <html>
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     5 <title>Insert title here</title>
     6     <script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
     7     <script type="text/javascript">
     8         
     9         $(function(){
    10             $("input").click(function(){
    11                 //0.1请求lujing
    12                 var url = "/jquery_day02/SendDataServlet";
    13                 //0.2请求参数 位json字符串
    14                 var params = {"username":"杰克","password":"123"};
    15                 /*
    16                  * 1
    17                  * 使用load(url, [data], [callback])函数加载
    18                  *  *不加请求参数则是get请求 
    19                  *  *加了请求参数是post请求 他的回调函数有三个参数
    20                  *  参数1:data响应数据 load()永远得到的是字符串 可以使用eval()变为json对象
    21                  */
    22 //                $(this).load(url,params,function(data){
    23 //                    var json = eval("("+data+")");
    24 //                    alert(json.message);
    25 //                });
    26 
    27                 /*
    28                  * 2$.get()全局函数,发送get请求
    29                  * jQuery.get(url, [data], [callback], [type])
    30                  * *你需要解决中文编码的问题 new String(username.getBygets("iso-8859-1","utf-8"));
    31                  *     *响应的数据,如果使用的是application/json;charset=utf-8,则jquery自动的将数据切换为json对象
    32                  *     *响应的数据,如果使用的是text/json;charset=utf-8,则回调函数返回的字符串,需要手动转换
    33                  *         使用参数4  type:返回内容格式,xml, html, script, json, text, _default。
    34                  *   设为"json"就返回json对象了
    35                  */
    36 //                $.get(url,params,function(data){
    37 //                    alert(data.message);
    38 //                },"json");
    39                 /*
    40                  * $.post() 请求时post 同上
    41                  */
    42 //                $.post()(url,params,function(data){
    43 //                    alert(data.message);
    44 //                },"json");
    45                 /*
    46                  * $.ajax();底层功能最强大
    47                  *     格式:$.ajax([settings])
    48                  *             参数setting:设置所有参数
    49                  *                 url:发送请求地址
    50                  *                 data:发送到服务器的数据
    51                  *              type:请求方式
    52                  *               success:成功的回到函数success(data, textStatus, jqXHR) data:服务器响应的数据
    53                  *                dataType:务器返回的数据类型 xml, html, script, json, text, _default
    54                  *                error:请求失败时调用此函数
    55                  */
    56                 $.ajax({
    57                     "url":url,
    58                     "data":params,
    59                     "type":"post",
    60                     "success":function(data){
    61                         alert(data.message);
    62                     },
    63                     "dataType":"json",
    64                     "error":function(){
    65                         alert("服务器请求繁忙");
    66                     }
    67                     
    68                     
    69                 });
    70             });
    71         });
    72     </script>
    73     
    74 </head>
    75 <body>
    76     
    77     <input type="button" value="发送ajax" />
    78     
    79     
    80 </body>
    81 </html>
  • 相关阅读:
    【风马一族_php】PHP与Mysql建立连接
    【风马一族_php】NO1_用php发出一声 Hi
    【风马一族_php】NO0_搭建web服务器
    【风马一族_mysql】mysql基本指令
    wnmp环境搭建
    appach2.4 + php7 +mysql5.7.14 配置
    常用样式
    jquery 格式化系统时间
    使用插件实现一般处理程序导出excel
    bootstrap分页
  • 原文地址:https://www.cnblogs.com/geyaofendou/p/6623340.html
Copyright © 2011-2022 走看看