AJAX动态给下拉框的option中赋值



  $.ajax({
      url: "/sales/saSettleAccount.do?actionType=queryRiskCode&codeType=queryRiskCodeAllSelect",  //要写绝对路径
      type: "POST",
      dataType: "json",
      async : false,
       error: function (XMLHttpRequest, textStatus, errorThrown) {
              //  displayMessage(XMLHttpRequest.status);
              //  displayMessage(XMLHttpRequest.readyState);
               // displayMessage(textStatus);
        },



         success : function(jsonOBJ)
         {
          var  jsonOBJs=[];
          for(var i=0;i              var option = new Option(jsonOBJ[i].riskCode+"-"+jsonOBJ[i].riskCName,jsonOBJ[i].riskCode);
                 riskCode.options.add(option);//riskCode为select标签的name
                 
             }
   var select = document.getElementById("riskCodeId");  
  for(var i=0; i            select.options[i].selected = true; 
    }
         }
     });

后台

  PrpDriskFindByConditionsCommand command = new PrpDriskFindByConditionsCommand(conditions);
  Collection result = (Collection) command.execute();
  for (Iterator iter = result.iterator(); iter.hasNext();) {
       PrpDriskDto prpDriskDto = (PrpDriskDto) iter.next();
   codeValues.add(prpDriskDto);
  }
  response.setContentType("text/html;charset=UTF-8");


  String riskCodeCollections= JSON.toJSONString(codeValues);

  response.getWriter().write(riskCodeCollections);


你可能感兴趣的:(java基础)