异步请求

<div class="cs-clear cs-ib">
               <span  style="float: left;margin-left:-20px;">
                    <label for="game">游戏名称:</label>
               </span>
               <span  style="float: left;">      
                    <select id="game" name="game" οnchange="GameServer.changeServer(this.value);
gameServerChannelInsert.reGetChannels('${basePath}');">
     
        <c:forEach items="${gameListMap}" var="map" varStatus="status" >  
         <option value="${map.key }"  <c:if test="${ map.key==game}">selected </c:if> >${map.value }</option>
        </c:forEach>
     </select>
   </span>
   <span  style="float: left;">    
                    <label for="server_null">游戏服务器:</label>  
               </span>
   <span  style="float: left;">
                    <select id="server_null" name="gameServer" style="display:none; " disabled="disabled" οnchange="
gameServerChannelInsert.reGetChannels('${basePath}')">
                         <option value="null">全部</option>
                    </select>  
                    <c:forEach items="${gameServerMap}" var="serverMap" varStatus="status" >  
                           <select id="server_${serverMap.key}" name="gameServer" style="display:none;" disabled="disabled" οnchange="
gameServerChannelInsert.reGetChannels('${basePath}') ">
                              <option value="null">全部</option>
                              <c:forEach items="${serverMap.value}" var="gameServerPO" varStatus="status" >  
           <option value="${gameServerPO.pk.gameServer }"   <c:if test="${ map.key==gameServer}">selected </c:if> >${gameServerPO.serverName  }</option>
        </c:forEach>    
                            </select>
    </c:forEach>
    <input type="hidden" id="lastGameId" name="lastGameId" value='${game }'/>
    <input type="hidden" id="lastGameServer" name="lastGameServer" value='${gameServer }'/>
               </span>
             
   <span  style="float: left;margin-left:-35px;">    
                    <label for="channel_null">频道:</label>  
                   
               </span>
   <span  style="float: left;" >
   
                     <select id="channel_null" name="channelId" style="display:none; " disabled="disabled">
                         <option value="null">全部</option>
                    </select>
               
                           <select id="channelId" name="channelId" >
                              <option value="null">全部</option>
                              <c:forEach items="${gameServerChannels}" var="item" varStatus="status" >  
           <option value="${item.channelId}"  <c:if test="${item.channelId==channelId}">selected </c:if>>${item.channelId}</option>
        </c:forEach>    
                            </select>
   
               </span>

</div>  

==============================================================================

var gameServerChannelInsert = {

"reGetChannels" : function(path) {
 var game = document.getElementById("game").value;
 var gameServerId = "server_"+game;
    var gameServer = document.getElementById(gameServerId).value;
    var url = path+'specialServer/reGetChannels.do';
    var queryData = $("#queryForm").serializeArray();  //把表单元素序列化成json格式的数据
    $.ajax({
        type: "POST",
        url: url,
        data: queryData,  // 相当于提交表单数据(后台能接收)
        async: true,
        cache: false,

  //    dataType: "json",
        success: function(data){
        $("#channelId").html(data);
        }
    });
   },

}

 

==============================================================================

 

   /**
    * 异步获取频道列表
    * @param response
    * @param game
    * @param gameServer
    * @throws IOException
    */
@RequestMapping
public void reGetChannels(HttpServletResponse response, String game,String gameServer) throws IOException {
 List<DimGameServerChannel> gameServerChannels = dimGameServerChannelService.getGameServerChannel(game, gameServer);
 List<String> channels = new ArrayList<String>();
 for (DimGameServerChannel gameServerChannel : gameServerChannels) {
  channels.add(gameServerChannel.getChannelId());
 }
 String channelsHtml = buildChannelsToHtml(channels);
 response.setContentType("text/plain; charset=gbk");
 PrintWriter writer = response.getWriter();
 writer.write(channelsHtml);
 writer.flush();
}

private String buildChannelsToHtml(List<String> channels) {
 StringBuilder channelsHtml = new StringBuilder();
 channelsHtml.append("<option value='null'>全部</option>");
 for(String channel : channels) {
  if(StringUtils.equals("null", channel)) {
   continue;
  }
  channelsHtml.append("<option value='").append(channel).append("'>").append(channel).append("</option>");
 }
 return channelsHtml.toString();
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值