如何解决波斯字符IE和FireFox Ajax asp的问题? [英] How to solve problem character farsi IE And FireFox ajax asp?

查看:53
本文介绍了如何解决波斯字符IE和FireFox Ajax asp的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决波斯字符IE和FireFox Ajax asp的问题?
这个项目是聊天室:
js文件:

how to solve problem character farsi IE And FireFox ajax asp?
this project is chat:
file js:

var chats = new Array();
var top = 100;
var left = 100;
function OpenChatBox(uid, chatid) {
    var win = window.open("ChatBox.aspx?uid=" + uid + "&cid=" + chatid, "ChatWindow" + chatid + document.getElementById('hidCurrentUser').value, "status=0,toolbar=0, menubar=0, width=450, height=550");
    top = top + 50;
    if (top > screen.availHeight - 550)
        top = 100;
    left = left + 50;
    if (left > screen.availWidth - 450)
        left = 100;
    
    win.moveTo(left, top);
    chats[chats.length] = win;
    return false;
}

function PingServer() {
    PingServerForMsg()
    setTimeout(PingServer, 5000);
}

var xmlHttp;
var requestURL = 'GetChatMsg.aspx';
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5") != -1) ? 1 : 0;
var is_opera = ((navigator.userAgent.indexOf("Opera6") != -1) || (navigator.userAgent.indexOf("Opera/6") != -1)) ? 1 : 0;
//netscape, safari, mozilla behave the same??? 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

function PingServerForMsg() {
       //Append the name to search for to the requestURL 
        var url = requestURL;

        //Create the xmlHttp object to use in the request 
        //stateChangeHandler will fire when the state has changed, i.e. data is received back 
        // This is non-blocking (asynchronous) 
        xmlHttp = GetXmlHttpObject(stateChangeHandler);

        //Send the xmlHttp get to the specified url 
        xmlHttp_Get(xmlHttp, url);   
}

//stateChangeHandler will fire when the state has changed, i.e. data is received back 
// This is non-blocking (asynchronous) 
function stateChangeHandler() {
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete') {
        //Gather the results from the callback 
        var str = xmlHttp.responseText;
        
        if (str != "" ) {
            //document.getElementById('txtMsg').value = str;
            //eval(str);
            var msgs = str.split('#');

            for (ind = 0; ind < msgs.length; ind++) {
                msgs[ind] = msgs[ind].replace("_@HASH__", "#");
                var msg = msgs[ind].split("&");
                msg[0] = msg[0].replace("_@AMP__", "&");
                msg[1] = msg[1].replace("_@AMP__", "&");
                msg[2] = msg[2].replace("_@AMP__", "&");            
                var blnExisting = false;
                for (iind = 0; iind < chats.length; iind++) {
                    try
                    {
                        if (chats[iind] != null && chats[iind].name == "ChatWindow" + msg[1] + document.getElementById('hidCurrentUser').value)
                        blnExisting = true;
                    }
                    catch(e){}
                }  
                if( blnExisting == false)
                    OpenChatBox(msg[0], msg[1]);
            }
        }
    }
}

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) {
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
}

function GetXmlHttpObject(handler) {
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    if (is_ie) {
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';

        //Attempt to create the object 
        try {
            objXmlHttp = new ActiveXObject(strObjName);
            objXmlHttp.onreadystatechange = handler;
        }
        catch (e) {
            //Object creation errored 
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
            return;
        }
    }
    else if (is_opera) {
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.');
        return;
    }
    else {
        // Mozilla | Netscape | Safari 
        objXmlHttp = new XMLHttpRequest();
        objXmlHttp.onload = handler;
        objXmlHttp. önerror = handler;
    }

    //Return the instantiated object 
    return objXmlHttp;
} 


服务器端代码:


server side code:

Response.Clear();
        Response.ClearContent();
        Response.AddHeader("Cache-Control", "no-cache, must-revalidate");

        DataSet ds   = GetMessage(HttpContext.Current.User.Identity.Name);
         String  strMsg= "";
        if (ds.Tables.Count > 0) {

            if (ds.Tables[0].Rows.Count > 0) {

                foreach( DataRow dr in ds.Tables[0].Rows){
                    if (strMsg.Length > 0)
                        strMsg += "#";
                  
                    strMsg += dr["Sender"].ToString() + "&";
                    strMsg += dr["ChatId"].ToString() + "&";
                    strMsg += dr["Msg"].ToString().Replace("&", "_@AMP__").Replace("#", "_@HASH__");
                }

            }
        }

        Response.Write(strMsg);

        Response.End();
    }
    private DataSet GetMessage(String strUid) 
    {
        DataSet dsMsgs = new DataSet();
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        con.Open();
        SqlCommand comm = new SqlCommand("stp_GetMessage", con);
        comm.CommandType = CommandType.StoredProcedure;
        SqlParameter paramSender = new SqlParameter( "@Uid", SqlDbType.VarChar, 10);
        paramSender.Value = HttpContext.Current.User.Identity.Name;
        comm.Parameters.Add(paramSender);

        if (Request.QueryString["cid"] != null) {
            SqlParameter paramChatId = new SqlParameter( "@ChatId", SqlDbType.VarChar, 100);
            paramChatId.Value = Request.QueryString["cid"];
            comm.Parameters.Add(paramChatId);
        }

        SqlDataAdapter da = new SqlDataAdapter(comm);
        da.Fill(dsMsgs);

        con.Close();
        return dsMsgs;
    }

推荐答案

我认为此问题与您在其他问题中报告的问题相同.
我给出了解决方案,请参阅:问题波斯语asp ajax吗? [^ ] .

请尝试避免重新发布问题.最好在原始帖子的页面上使用改善问题".

—SA
I think this problem is the same as the one you reported in your other question.
I gave the solution, please see: problem persian language asp ajax?[^].

Please try to avoid re-posting questions. Better use "Improve question" at the page of your original post.

—SA


这篇关于如何解决波斯字符IE和FireFox Ajax asp的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆