//创建ajax对象函数 function createLink(){ if(window.ActiveXObject){ var newRequest = new ActiveXObject("Microsoft.XMLHTTP"); }else{ var newRequest = new XMLHttpRequest(); } return newRequest; }
//如果文本框为空,不发送请求 if($("#searchtext").val().length==0||$("#searchtext").val().length>10){ $("#suggest_ul").hide(0); return; } //发送请求 http_request = createLink();//创建一个ajax对象 if(http_request){ var sid = $("#searchtext").val(); var url = "contentSearchAction!getSynonyms.action"; var data = "keywords="+encodeURI(sid); //alert(data) http_request.open("post",url,true); http_request.setRequestHeader("content-type","application/x-www-form-urlencoded");
//处理返回结果 function dealresult(){ if(http_request.readyState==4){ //等于200表示成功 if(http_request.status==200){ if(http_request.responseText=="no"){ $("#suggest_ul").hide(0); return;
} $("#suggest_ul").show(0); var res = eval("("+http_request.responseText+")"); var contents=""; for(var i=0;i<res.length;i++){ var keywords = res[i].keywords; contents=contents+"<li onclick='onChangehoverLi(this);' class='suggest_li"+(i+1)+"'>"+keywords+"</li>";