<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是查詢生成的字段