json服务器端
/**
* 根據(jù)品牌id動(dòng)態(tài)加載標(biāo)的物
* @return
* @throws DataBaseException
* @throws IOException
*/
public String loadModel() throws DataBaseException, IOException{
HttpServletRequest request=ServletActionContext.getRequest();
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("application/x-javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
String brandId = request.getParameter("brandId");
List phones = this.phoneService.queryMobilByBrandId(Integer.parseInt(brandId));
if(phones!=null&&phones.size()>0){
//把集合對(duì)象轉(zhuǎn)換為json對(duì)象
JSONArray json=JSONArray.fromObject(phones);
out.println(json.toString());
out.close();
}else{
out.println("[{id:0,model:'請(qǐng)選擇'}]");
out.close();
}
return SUCCESS;
}
alert(value);
$.ajax({
type: "post",
url: "supply!loadPhone.do",
data: ({brandId: value}),
success: function(data){
var objs=eval("("+data+")");
var $phone=$("#phone");
$phone.empty();
//$phone.append("<option value='0'>..請(qǐng)選擇..</option>");
for(var i=0;i<objs.length;i++){
$phone.append("<option value='"+objs[i].id+"'>"+objs[i].model+"</option>");
}
}
});
}
* 根據(jù)品牌id動(dòng)態(tài)加載標(biāo)的物
* @return
* @throws DataBaseException
* @throws IOException
*/
public String loadModel() throws DataBaseException, IOException{
HttpServletRequest request=ServletActionContext.getRequest();
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("application/x-javascript;charset=UTF-8");
PrintWriter out = response.getWriter();
String brandId = request.getParameter("brandId");
List phones = this.phoneService.queryMobilByBrandId(Integer.parseInt(brandId));
if(phones!=null&&phones.size()>0){
//把集合對(duì)象轉(zhuǎn)換為json對(duì)象
JSONArray json=JSONArray.fromObject(phones);
out.println(json.toString());
out.close();
}else{
out.println("[{id:0,model:'請(qǐng)選擇'}]");
out.close();
}
return SUCCESS;
}
????????????
???
?????????????
function loadPhone(value){alert(value);
$.ajax({
type: "post",
url: "supply!loadPhone.do",
data: ({brandId: value}),
success: function(data){
var objs=eval("("+data+")");
var $phone=$("#phone");
$phone.empty();
//$phone.append("<option value='0'>..請(qǐng)選擇..</option>");
for(var i=0;i<objs.length;i++){
$phone.append("<option value='"+objs[i].id+"'>"+objs[i].model+"</option>");
}
}
});
}
????????
???
<select id="brand" name="brandId" onchange="loadPhone(this.options[this.options.selectedIndex].value)">轉(zhuǎn)載于:https://www.cnblogs.com/linjiqin/archive/2011/08/16/2140361.html
超強(qiáng)干貨來(lái)襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
- 上一篇: fedora 15中使用evolutio
- 下一篇: 矩形嵌套问题