zoukankan      html  css  js  c++  java
  • jquery请求servlet实现ajax异步请求

    欢迎访问个人博客:www.yyxxk.com

    ajax可以发送异步请求实现无刷新效果,但是使用javascript比较麻烦,就query提供了一些封装的方法 ,可以使得操作更为简单:

    $.ajax()方法:

    function sendRequest() {
            $.ajax({
                url: "Hello",
                type: "GET",
                dataType: "txt",
                data: "name=zhangsan",
                complete: function(result){
                    alert(result.responseText);
                }
            });
        }


    $.get()方法:

    function sendRequestByGet(){
            $.get("Hello","name=lisi",function(result){
                alert(result);
            });
        }

    $.post()方法:

    function sendRequestByPost(){
            $.post("Hello","name=wangwu",function(result){
                alert(result);
            });
        }

    $.load()方法:

        //load代码等效使用如下$get()方法
        /*
        $get(url, data,  function(result){
                    //将result数据填充到页面元素中
            $(“#h2”).html(result);   
        });
        */
    
        function load(){
            $("h2").load("Hello","name=hahaha");
        }

    以上异步请求的Hello文件:

    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            String name=req.getParameter("name");
            resp.getWriter().print(name);
        }
  • 相关阅读:
    (水题)洛谷
    (水题)洛谷
    洛谷
    (水题)洛谷
    POJ
    poj 3061(二分 or 尺取法)
    poj 2456(二分)
    poj 1064(二分答案)
    POJ 2559(单调栈)
    STL
  • 原文地址:https://www.cnblogs.com/javayuan/p/5388547.html
Copyright © 2011-2022 走看看