<input id="allcode" name="allcode" type="text" style="width: 150px" class="inputxt" datatype="*" readonly="readonly" >
<input type="button" value="查询" οnclick="javascript:allCodeQuery();">
js代码片段
<script type="text/javascript">
function allCodeQuery(){
var code=$('#code').val();
if(code == "" || code == undefined){
alert("请填写产品编码");
return;
}
$.ajax({
type : 'POST',
url : "wsProductController.do?allCodeChoose",
data : {code:code},
dataType : "json",
success : function(data) {
$('#allcode').val(data.obj);
if(!data.success){
alert("没有查到该产品对应的集团编码,默认为产品编码");
}
},
error: function() {// 请求失败处理函数
alert("执行异常");
}
});
}
</script>
/**
* 根据输入的产品编码查询集团编码
*
* @return
*/
@RequestMapping(params = "allCodeChoose")
@ResponseBody
public AjaxJson allCodeChoose(HttpServletRequest request) {
AjaxJson j = new AjaxJson();
String code=request.getParameter("code");
String allcode=wsProductService.queryAllcode(code);
if(allcode==null || allcode.isEmpty() ){
j.setObj(code);
j.setSuccess(false);
return j;
}else{
j.setObj(allcode);
return j;
}
}
注意:code是要获取的字段,allcode是查询生成的字段