• jquery解析jsion


    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    
    <title>ajax</title>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
    
    
    //var jsons={"firstName":"tom","lastName":"jack"};
    
    /* var jsons={
                    "people":[
                              {"firstName":"tom","lastName":"McLaughlin","email":"aaaa"},
                              {"firstName":"jack","lastName":"Hunter","email":"bbbb"},
                              {"firstName":"lucy","lastName":"Harold","email":"cccc"}
                          ]
                      };*/
    
    
    /* var jsons={
                                "programmers": [{
                                    "firstName": "Brett",
                                    "lastName": "McLaughlin",
                                    "email": "aaaa"
                                }, {
                                    "firstName": "Jason",
                                    "lastName": "Hunter",
                                    "email": "bbbb"
                                }, {
                                    "firstName": "Elliotte",
                                    "lastName": "Harold",
                                    "email": "cccc"
                                }],
                                "authors": [{
                                    "firstName": "Isaac",
                                    "lastName": "Asimov",
                                    "genre": "sciencefiction"
                                }, {
                                    "firstName": "Tad",
                                    "lastName": "Williams",
                                    "genre": "fantasy"
                                }, {
                                    "firstName": "Frank",
                                    "lastName": "Peretti",
                                    "genre": "christianfiction"
                                }],
                                "musicians": [{
                                    "firstName": "Eric",
                                    "lastName": "Clapton",
                                    "instrument": "guitar"
                                }, {
                                    "firstName": "Sergei",
                                    "lastName": "Rachmaninoff",
                                    "instrument": "piano"
                                }]
                            };*/
    
    /*var jsons={"data":[
                         {"queryLeftNewDTO":
                               {"station_train_code":"G133",
                                 "start_station_name":"北京南","end_station_name":"上海虹桥"}
                         }  
    
                         ]};
                             $.each(jsons.data,function(i,dom){
                            alert('车次'+dom.queryLeftNewDTO.station_train_code+"
    始发站"+dom.queryLeftNewDTO.start_station_name);
                        });
    
     */
    
    var jsons= [{"age":20,"name":"jack"},{"age":20,"name":"tom"}];         
    
    $.each(jsons,function(i,dom){
        alert(dom.age);
    });    
    
    window.onload=function(){
        btn.onclick=function(){
            //myajax();
            jqueryajax();
        };
    };
    
    //建立一个xhr对象,并且判定了兼容性
    function createxhr(){
        var xhr=null;
        //能力检测
        if(window.XMLHttpRequest){
            xhr=new XMLHttpRequest();//非IE浏览器
        }else{
            //IE低版本浏览器
            xhr=new ActiveXObject("Microsoft.XMLHttp");
        }
        return xhr;
    }
    function  jqueryajax(){
        $.ajax({
            type: 'POST',
            url: "/DayAjax/servlet/DoAjaxServlet",
            data: 'name=张三',
            success: function(data){
            msg.innerHTML+=data;
        }});
    }
    
    function myajax(){
        //01.ajax请求后台的一个servlet
        var xhr=createxhr();
        //02.发送一个ajax请求,通过open方法
        xhr.open('post','/DayAjax/servlet/DoAjaxServlet',true);
        //03.设置回调函数
        xhr.onreadystatechange=function(){
            //服务器端处理数据的状态      状态码
            if(xhr.readyState==4&&xhr.status==200){ //server已经成功的回送数据到client浏览器
                //核心对象,提供一个属性或者方法,帮助你获取到回送的数据
                var data=xhr.responseText;
                //将内存中的data,借助页面上的一个标签显示
                msg.innerHTML+=data;
            }
        };
        //04.请求头里,叫 ContentType
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        //05.发送
        xhr.send("name=张三");
    
    }
    </script>
    </head>
    
    <body>
    <input type="button" id="btn" value="ajax" />
    <div id="msg"></div>
    </body>
    </html>

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>">
    <title>ajax</title><script type="text/javascript" src="js/jquery-1.8.3.min.js"></script><script type="text/javascript">

    //var jsons={"firstName":"tom","lastName":"jack"};
    /* var jsons={       "people":[                 {"firstName":"tom","lastName":"McLaughlin","email":"aaaa"},                 {"firstName":"jack","lastName":"Hunter","email":"bbbb"},                 {"firstName":"lucy","lastName":"Harold","email":"cccc"}             ]         };*/

    /* var jsons={           "programmers": [{               "firstName": "Brett",               "lastName": "McLaughlin",               "email": "aaaa"           }, {               "firstName": "Jason",               "lastName": "Hunter",               "email": "bbbb"           }, {               "firstName": "Elliotte",               "lastName": "Harold",               "email": "cccc"           }],           "authors": [{               "firstName": "Isaac",               "lastName": "Asimov",               "genre": "sciencefiction"           }, {               "firstName": "Tad",               "lastName": "Williams",               "genre": "fantasy"           }, {               "firstName": "Frank",               "lastName": "Peretti",               "genre": "christianfiction"           }],           "musicians": [{               "firstName": "Eric",               "lastName": "Clapton",               "instrument": "guitar"           }, {               "firstName": "Sergei",               "lastName": "Rachmaninoff",               "instrument": "piano"           }]       };*/
    /*var jsons={"data":[                     {"queryLeftNewDTO":                           {"station_train_code":"G133",                        "start_station_name":"北京南","end_station_name":"上海虹桥"}                     }  
                         ]};        $.each(jsons.data,function(i,dom){          alert('车次'+dom.queryLeftNewDTO.station_train_code+" 始发站"+dom.queryLeftNewDTO.start_station_name);           });
     */


    var jsons= [{"age":20,"name":"jack"},{"age":20,"name":"tom"}];         
    $.each(jsons,function(i,dom){alert(dom.age);
    });    




    window.onload=function(){btn.onclick=function(){//myajax();jqueryajax();};};
    //建立一个xhr对象,并且判定了兼容性function createxhr(){var xhr=null;//能力检测if(window.XMLHttpRequest){xhr=new XMLHttpRequest();//非IE浏览器}else{//IE低版本浏览器xhr=new ActiveXObject("Microsoft.XMLHttp");}return xhr;}

    function  jqueryajax(){$.ajax({type: 'POST',url: "/DayAjax/servlet/DoAjaxServlet",data: 'name=张三',success: function(data){msg.innerHTML+=data;}});

    }
    function myajax(){//01.ajax请求后台的一个servletvar xhr=createxhr();//02.发送一个ajax请求,通过open方法xhr.open('post','/DayAjax/servlet/DoAjaxServlet',true);//03.设置回调函数xhr.onreadystatechange=function(){//服务器端处理数据的状态      状态码if(xhr.readyState==4&&xhr.status==200){ //server已经成功的回送数据到client浏览器//核心对象,提供一个属性或者方法,帮助你获取到回送的数据var data=xhr.responseText;//将内存中的data,借助页面上的一个标签显示msg.innerHTML+=data;}};//04.请求头里,叫 ContentTypexhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");//05.发送xhr.send("name=张三");
    }</script></head>
    <body><input type="button" id="btn" value="ajax" /><div id="msg"></div></body></html>













  • 相关阅读:
    获取一张表的所有列
    SqlServer查询数据库所有用户表的记录数
    IE和Firefox在JavaScript方面的兼容性(转)
    ASP.NET2.0调用MySql的存储过程
    javascript在中ie与firefox的区别与解决方案(转)
    针对Firefox兼容性,要注意的一些问题 (转)
    JavaScript Import XML Document
    Remote建立分析
    sql2000和文本文件的写入和读取(转)
    firefox与IE对javascript和CSS的区别(转)
  • 原文地址:https://www.cnblogs.com/go4mi/p/5551975.html
Copyright © 2020-2023  润新知