当你的项目过于老旧,无法使用jQuery 实现ajax
请参考原生js的方式:
function myAjax(id,type)
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xmlhttp=new XMLHttpRequest();
}
else
{
// IE6, IE5 浏览器执行代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
var url = "/aaaa/test.action?id="+id+"&type="+type;//访问地址+传参
xmlhttp.open("POST",url,true);
xmlhttp.send();
}
后端代码:
//查询某合同的不同类型附件的个数
public void test() throws Exception {
//接参数
String fid = request.getParameter("fid");
String type = request.getParameter("type");
//service层调用后台查询数据
int count = cService.checkCount(fid,type);
//回写数据
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.print("此类型有"+count +"个附件!");
out.flush();
}
需要请自取!