中文出现乱码
搜索页面<form action="CaiGou_Sql.asp" method="post" name="searchs" autocomplete="off">
型号规格:<input type="text" name="keyword" style="width:120px" id="keyword" onBlur="keydown()" onKeyUp="keyupdeal(event);keydown();" onKeyDown="keydowndeal(event);" onClick="keyupdeal(event);document.getElementById('JH_ShuLiang').value = '';" > <!--getElementById('JH_ShuLiang').value = '';" 这里是当点击keyword文本框时,清空JH_ShuLiang中的值-->
<div id="suggest"></div></form>
js页面代码
var j=-1;
var temp_str;
var inputField;
var $=function(node){
return document.getElementById(node);
}
var $$=function(node){
return document.getElementsByTagName(node);
}
function ajax_keyword(){
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4){
if (xmlhttp.status==200){
var data=xmlhttp.responseText;
$("suggest").innerHTML=data;
j=-1;
}
}
}
//var post="keyword="+document.getElementById("keyword").value;
//post=encodeURI(post);
//post=encodeURI(post); //最重要的部分,两次调用encodeURI ,就是编码两次
//xmlhttp.open("POST","CaiGou_Sql.asp",true);
//xmlhttp.setRequestHeader("contentLength",post.length);
//xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//xmlhttp.send(post);
//var res=xmlhttp.responseText;//接收返回的数据
//document.getElementById("keyword").innerHTML=res;
//escape(document.getElementById("txt").value);
xmlhttp.open("post", "CaiGou_Sql.asp", true);
//xmlhttp.setRequestHeader('(encryptValue,"UTF-8")');
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send("keyword="+escape($("keyword").value));
}
function keyupdeal(e){
var keyc;
if(window.event){
keyc=e.keyCode;
}
else if(e.which){
keyc=e.which;
}
if(keyc!=40 && keyc!=38){
ajax_keyword();
temp_str=$("keyword").value;
}
}
function set_style(num){
for(var i=0;i<$$("li").length;i++){
var li_node=$$("li")[i];
li_node.className="";
}
if(j>=0 && j<$$("li").length){
var i_node=$$("li")[j];
$$("li")[j].className="select";
}
}
function mo(nodevalue){
j=nodevalue;
set_style(j);
}
function form_auto(){
if(j>=0 && j<$$("li").length){
$("keyword").value=$$("li")[j].childNodes[0].nodeValue;
}
}
function hide_suggest(){
var nodes=document.body.childNodes
for(var i=0;i<nodes.length;i++){
if(nodes[i]!=$("keyword")){
$("suggest").innerHTML="";
}
}
}
function keydowndeal(e){
var keyc;
if(window.event){
keyc=e.keyCode;
}
else if(e.which){
keyc=e.which;
}
if(keyc==40 || keyc==38){
if(keyc==40){
if(j<$$("li").length){
j++;
if(j>=$$("li").length){
j=-1;
}
}
if(j>=$$("li").length){
j=-1;
}
}
if(keyc==38){
if(j>=0){
j--;
if(j<=-1){
j=$$("li").length;
}
}
else{
j=$$("li").length-1;
}
}
set_style(j);
if(j>=0 && j<$$("li").length){
$("keyword").value=$$("li")[j].childNodes[0].nodeValue;
}
else{
$("keyword").value=temp_str;
}
}
}
获取数据的页面
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Comm.asp"-->
<%
dim keyword
keyword=trim(request.Form("keyword")) '接收ajax发送的参数
if keyword="" then response.End()
'------------------------------------------------------------------
set rs=server.CreateObject("adodb.recordset")
sql="select * from FT_LeiBie where TongJin_YaLi like '%"&keyword&"%' or YingCun_YaLi like '%"&keyword&"%'"
rs.open sql,Comm,1,3
'response.Write("人才")
'------------------------------------------------------------------
'--------如果没有找到的话,返回0
'--------如果找到的话,返回所有匹配的项目
if not (rs.eof and rs.bof) then
response.Write("<ul>")
for i=0 to 9
if rs.eof then exit for
response.Write("<li value="""&i&""" onclick=""form_auto()"" onmouseover=""mo(this.value)"">"&rs("TongJin_YaLi")&"<span> "&rs("YingCun_YaLi")&"</span></li></li>")
rs.movenext
next
end if
rs.close
set rs=nothing
response.write "<script language=javascript>history.go(-1);</script>"
%>
像百度一样的那样搜索页面,但是获取到得中文就出现乱码,求解 求解求解求解