简单示例:
前段js请求:
$.getJSON(ctx +"/sale/order/OrderNew/testCurrencyDomain.action" , {"domain" : encodeURI(domainName) ,"tt":(new Date()).getTime()},function(json){ if(json.flag==false){ $("#textDomain").text("域名 "+json.domain+" 不可用,请重新输入!"); $("#domainVerify").val("false"); //用来判断域名是否点验证 }else{ $("#textDomain").text("恭喜您!!域名 "+json.domain+" 可以注册!!"); $("#domainVerify").val("true"); //用来判断域名是否点验证 } });
后端java响应:
/**
* 验证通用网址域名
*
* @return
* @throws IOException
*/
@Action(value = "testCurrencyDomain", results = {})
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public void testCurrencyDomain() throws IOException {
HttpServletResponse res = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
res.setCharacterEncoding("UTF-8");
res.setContentType("text/json; charest=utf-8");
StringBuilder sb = new StringBuilder();
boolean flag = false;
try {
flag = rrpService.checkKeyWord(URLDecoder.decode(domain, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
} finally {
sb.append("{");
sb.append("\"domain\":\"" + URLDecoder.decode(domain, "UTF-8") + "\"");
sb.append(",\"flag\":" + flag);
sb.append("}");
res.getWriter().print(sb.toString());
}
}