zoukankan      html  css  js  c++  java
  • JSP + AJAX完整实例及代码

    (1)发送请求index.jsp,注意引入jquery.min.js文件

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="GB18030"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    <script src="jquery.min.js"></script>
    <script>
        jQuery(document).ready(function($) {
           $('#send').click(function(){
            $.ajax({
                type: "POST",
                url: "ajax.jsp",
                async:false,
                data: {name:"name", content:"content"},
               // dataType: "json",
                dataType: "text",
                success: function(data){
               
                //alert(JSON.stringify(data));//使用JSON方法,需引入jar包,json-java.jar、json-lib.jar
                alert(data);
                },
                error: function(e) { 
                alert(e); 
                }
            });
       });
    });
    </script>
    </head>
    <body>
        <div>
            <button id="send">test</button>
        </div>
    </body>
    </html>

    (2)接受请求并返回值ajax.jsp

    <%@ page contentType="text/html; charset=gb2312" %>     
    <%
        String id=request.getParameter("name");
        System.out.println("Parameter is :"+id);
        //out.print("{3:8,9:4}");//json
        out.print("sdfwsuueiw");
    %>
  • 相关阅读:
    up6-chrome 45+安装教程
    HttpUploader7-授权码配置
    jsp-MySQL连接池
    WordPaster2-正式包布署说明
    HTTP文件上传插件开发文档-ASP
    HTTP文件上传插件开发文档-JSP
    eWebEditor9.x整合教程-Xproer.WordPaster
    42. Trapping Rain Water
    41. First Missing Positive
    40. Combination Sum II
  • 原文地址:https://www.cnblogs.com/langdangyunliu/p/4079736.html
Copyright © 2011-2022 走看看