function getPhoneInfoByModelId(model_id){
if(model_id){
$.ajax({
url: "${applicationScope.rootpath}phoneassess/getPhoneInfoByModelId.action",
type: "post",
dataType:"json",
data: {model_id:model_id},
success: function (jsonText) {
if(jsonText){
$.each(jsonText,function(i,item){
var IMAGE_PATH = item.IMAGE_PATH;
var MODEL_ALIS = item.MODEL_ALIS;
//alert(IMAGE_PATH+"--"+MODEL_ALIS);
if(IMAGE_PATH){
var imgIcon = "";
$("#phonemodelimg").html(imgIcon);
}
if(MODEL_ALIS){
$("#phonemodelalis").html(MODEL_ALIS);
}
});
}
}
});
}
}
/*AjaxTestAction.java*/
//获得手机信息
public String getPhoneInfoByModelId(){
String model_id = this.getHttpRequest().getParameter("model_id");
List> brandList = null;
if(null != model_id && model_id.length() > 0){
brandList = this.phoneAssessService.getPhoneInfoByModelId(model_id);
for(int i = 0,len=brandList.size();i
formatToJsonHashMap(brandList.get(i));
}
JSONArray jsArray = JSONArray.fromObject(brandList);
this.setTextAjax(jsArray.toString());
}
return NONE;
}
//公共方法:格式化空值和日期
public void formatToJsonHashMap(Map hashMap){
Iterator iter = hashMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String key = entry.getKey().toString();
if(entry.getValue()!=null&&"java.sql.Date".equals(entry.getValue().getClass().getName())){
hashMap.put(key, DateUtil.format((Date)entry.getValue(), "yyyy-MM-dd"));
}
}
}
/**
* ajax返回html,包括json形式
*
* @param responseContent
*/
public void setTextAjax(String responseContent) {
try {
HttpServletResponse response = getHttpResponse();
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setHeader("Pragma", "No-cache");
response.setHeader("Content-Type", "text/html");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
PrintWriter out = response.getWriter();
out.print(responseContent);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
// ajaxResponse = new StringBufferInputStream(responseContent);
}