ajax onkyeup事件 模糊查询

function mhcx(o,rowID){//模糊查询
clearInterval(d);
var zbmc = document.getElementById("ZBBM"+rowID).value;
if(zbmc==""||rowID==""){return}
var zbxh1 = o.value;
var div = document.getElementById("div1");
div.style.display="none";
div.innerHTML = "";


var input = document.activeElement;    
oRect = input.getBoundingClientRect();
var x=oRect.left
var y=oRect.top
  div.style.position='absolute';
  var scrollY = getScrollTop()
  div.style.left=x;
div.style.top=y+25+scrollY;

  $.ajax({
url:"Mhcx.jsp",
type:"post",
data:{"ZBBM":zbxh1,ZBMC:zbmc},
success : function(arrayStr){
if(arrayStr.length==0){
div.style.display="none";
}else{
div.style.display="block";
var array = arrayStr.split("->");
var span="";
for(var i=0;i var zbxh = array[i];
if(zbxh.length>0){
if(i%2==0){
span +=""+zbxh+"
";
}else{
span +=""+zbxh+"
";
}
div.innerHTML=span;
}
}

}
},
error:function(){div.style.display="none";}
});   

}


public class Mhcx extends HttpServlet{
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
resp.setContentType("text/html;charset=GBK");
String zbxh=req.getParameter("ZBBM");
String zbmc=req.getParameter("ZBMC");
String sql="SELECT DISTINCT(ZBXH) ZBXH FROM TBL_ZBGL_KCXX WHERE ZBMC =? AND ZBXH LIKE '%'||?||'%' AND SCBJ='0' AND rownum>0 AND rownum<8 AND ZBXH!='null'";
DBHelper dbHelper = new DBHelper();

List> list=dbHelper.query(sql,new String[]{zbmc,zbxh},new int[]{Types.VARCHAR,Types.VARCHAR}); 
   String arrayStr = "";
   for(int i=0;i    Map map = list.get(i);
    String zbxh1 = map.get("ZBXH");
    arrayStr=arrayStr+zbxh1+"->";


   }
   PrintWriter pw=resp.getWriter();
   pw.write(arrayStr);
   pw.flush();
   pw.close();


}
}

你可能感兴趣的:(ajax,函数,js)