zoukankan      html  css  js  c++  java
  • ajax实际的应用

    假设两个选择框,前面一个是省份,后面一个是地级市。当选择某一省份的时候,后面的选择框会有此省份对应的地级市。可以根据ajax来实现。

    function load{

      if(true){
          var baseURL = "/prpall/processPrpDBusiLevel.do?actionType=getCityInfo";
          var url = baseURL + "&busiUpperCode=" + trim(field1.value)+"&busiLevel="+level;
          xmlRequest = createXMLHttpRequest1();
          xmlRequest.onreadystatechange = processCityCodeStateChange;
          try {
              xmlRequest.open("POST",url,false);
          }catch (e) {
              alert(e);
          }
          xmlRequest.send(null);

      }

    }

    function processCityCodeStateChange(){
      if (xmlRequest.readyState == 4) { // Complete
          if (xmlRequest.status == 200) { // OK response
              var retValue = trim(xmlRequest.responseText);
              if(retValue!=""){
                if(retValue.indexOf("error:")==0){
                }else{         
                  var optionArray  =  retValue.split(GROUP_SEPARATOR);
                  var value;  
                  var text; 
                  field2.add(new Option("请选择","",true,true));
                  var order = 0;
                  for(var i=0;i<optionArray.length;i++){
                    var optionText = optionArray[i].split(FIELD_SEPARATOR);
                    value = optionText[0];  
                    text = optionText[1];
                    field2.add(new Option(text,value));
                  }
                }
                field2.add(new Option("其他城市","999999"));
              }
             
          } else {
              alert("Problem: " + xmlRequest.statusText);
          }
      }

    function createXMLHttpRequest1() {
        try {
        // Attempt to create it "the Mozilla way"
            if (window.XMLHttpRequest) {
                return new XMLHttpRequest();
            }
        // Guess not - now the IE way
            if (window.ActiveXObject) {
                return new ActiveXObject(getXMLPrefix() + ".XmlHttp");
            }
        }
        catch (ex) {
        }
        return false;
    }

     服务器端(jsp):

    <%
    UIRateFromInfoAction uiRateFromInfoAction= new UIRateFromInfoAction();
    OutputStream outputStream= response.getOutputStream();
    String provinceCode= request.getParameter("provinceCode");
    String cityCode= request.getParameter("cityCode");
    String districtCode= request.getParameter("districtCode");
    String constructCode= request.getParameter("constructCode");
    double rate = uiRateFromInfoAction.getRate(provinceCode, cityCode,districtCode, constructCode);
    BigDecimal bRate= new BigDecimal(rate);
    bRate = bRate.setScale(2, BigDecimal.ROUND_HALF_UP);
    String rateString= bRate.toString();

    try {
     outputStream.write(rateString.getBytes());
     outputStream.flush();
    } catch (Exception e) {
     throw e;
    }finally{
     outputStream.close();
    }

    %>

  • 相关阅读:
    Ubuntu(以16.04 server版为例)在VMware上安装及网络配置
    Ubuntu上面python虚拟环境的配置及mysql和redis安装
    json和pickle
    sqlalchemy第四部分
    sqlalchemy第三部分
    sqlalchemy第二部分
    线程
    文件处理
    文件流
    集合框架类
  • 原文地址:https://www.cnblogs.com/westward/p/5643580.html
Copyright © 2011-2022 走看看