• ajax异步刷新


    前台js 

     1 <script type="text/javascript">
     2 
     3   function getLands() {
     4   
     5       $.ajax({
     6         url:"httpserver.do?doPost&userQygs="+$("#userQygs").val(),
     7         type:"POST",
     8         dataType:"text",
     9       
    10         success:function(data){
    11        
    12          if(data==null||data==""){
    13             
    14             alert("目前没有地块可供选择,请先绘制地块!");
    15             location.href ="gpadd.do?toArcgis&state=1";
    16          }else{
    17        
    18             var lands=data.split(",");
    19          
    20            //获得前台的div  
    21            var insertDiv = document.getElementById("land");  
    22            //定义向前台插入的内容为空  
    23            insertDiv.innerHTML = "";  
    24            var chkinfo;  
    25            var chkDIV;  
    26            //var txtinfo;  
    27            //解析从服务器获得的数据,循环添加复选框  
    28            for (var i = 0; i < lands.length-1; i++) {  
    29                //为每一个复选框创建一个DIV  
    30                chkDIV = document.createElement("div");  
    31                //每一个复选框用input创建,类型为checkBox  
    32                chkinfo = document.createElement("input");  
    33                chkinfo.name = "landDkbh";  
    34                chkinfo.id = "landDkbh";  
    35                chkinfo.type = "checkbox";  
    36               // chkinfo.onclick = test;  
    37                //将每一个chinesename为复选框赋值  
    38                chkinfo.value = lands[i];  
    39               //将复选框添加到Div中  
    40                chkDIV.appendChild(chkinfo);  
    41                //为Div设置样式  
    42                chkDIV.style.height = "50px";  
    43                chkDIV.style.width = "150px";  
    44                chkDIV.style.float = "left";  
    45                chkDIV.align = "left";  
    46                chkDIV.appendChild(document.createTextNode(lands[i]));  
    47                //将创建的div添加到前台预留的DIV下  
    48                insertDiv.appendChild(chkDIV);          
    49            }  
    50            }
    51         }
    52     });
    53  
    54  }

    后台

     1 package org.lq.ssm.gp.controller;
     2 
     3 import java.io.IOException;
     4 import java.io.PrintWriter;
     5 
     6 import javax.annotation.Resource;
     7 import javax.servlet.ServletException;
     8 import javax.servlet.http.HttpServlet;
     9 import javax.servlet.http.HttpServletRequest;
    10 import javax.servlet.http.HttpServletResponse;
    11 
    12 import org.lq.ssm.gp.service.LandUserBiz;
    13 import org.springframework.stereotype.Controller;
    14 import org.springframework.web.bind.annotation.RequestMapping;
    15 @SuppressWarnings("serial")
    16 @Controller
    17 @RequestMapping("httpserver.do")
    18 public class httpserverController extends HttpServlet{
    19     
    20     @Resource(name="landUserAction")
    21     private LandUserBiz landUserBiz;
    22     
    23     
    24     public void doGet(HttpServletRequest request, HttpServletResponse response)
    25             throws ServletException, IOException {
    26     
    27         response.setContentType("text/html;charset=gbk");
    28         response.setHeader("Cache-Control", "no-cache");
    29         response.setCharacterEncoding("gbk");
    30         PrintWriter out=response.getWriter();
    31         request.setCharacterEncoding("gbk");
    32         //获取搜索框输入的内容
    33       
    34         String userqygs=request.getParameter("userQygs");
    35         userqygs=new String(userqygs.getBytes("iso-8859-1"), "gbk");
    36         System.out.println("区域:"+userqygs);
    37       
    38         String res=landUserBiz.getLands(userqygs);
    39         System.out.println("字符串:"+res);
    40         //response.getWriter().write(res);
    41         out.write(res);
    42      
    43       
    44     }
    45 
    46     @RequestMapping(params="doPost")
    47     public void doPost(HttpServletRequest request, HttpServletResponse response)
    48             throws ServletException, IOException {
    49        
    50         doGet(request, response);
    51 
    52     }
    53 
    54 
    55     public LandUserBiz getLandUserBiz() {
    56         return landUserBiz;
    57     }
    58 
    59 
    60     public void setLandUserBiz(LandUserBiz landUserBiz) {
    61         this.landUserBiz = landUserBiz;
    62     }
    63     
    64    
    65 }
  • 相关阅读:
    学习进度条
    0302我的感想
    1217实验四 递归下降语法分析程序设计
    1118 实验三 有限自动机的构造与识别
    1112我的访问与评论日记
    1014 我的C语言文法定义与C程序推导过程
    0917词法分析
    命令解释程序的编写
    构建之法前三章读后感
    复利计算4.0
  • 原文地址:https://www.cnblogs.com/xiaotian-222/p/6775424.html
Copyright © 2020-2023  润新知