| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:中文出现乱码
只看楼主 加入收藏
zdloveday
Rank: 2
等 级:论坛游民
帖 子:221
专家分:96
注 册:2008-9-5
结帖率:68.89%
收藏
已结贴  问题点数:20 回复次数:3 
中文出现乱码
搜索页面
<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 = '';" >&nbsp;&nbsp;<!--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>&nbsp;"&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>"

%>

像百度一样的那样搜索页面,但是获取到得中文就出现乱码,求解  求解求解求解
搜索更多相关主题的帖子: keyword action method 文本框 
2013-01-05 17:18
zdloveday
Rank: 2
等 级:论坛游民
帖 子:221
专家分:96
注 册:2008-9-5
收藏
得分:0 
只是搜索的时候出现中文的时候,弹出对话框来是乱码
但是在数据显示页面中文又是好的,怎么弄了?

不懂----就无耻的下问吧----
2013-01-05 17:22
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:7 
把源码打包上传,要试一下才知道

----我怎能在别人的苦难面前转过脸去----
2013-01-05 22:50
ysf0181
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
收藏
得分:7 
乱码一般是js语法格式不对或者参数格式不对。

ASP讨论QQ群:251346273
2013-01-06 14:01
快速回复:中文出现乱码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038111 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved