472,127 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Decoding data in ASP posted via AJAX

Hi All,

I was not sure which forum to post the message to since the problem related to ASP/AJAX, but decided to post it here.
I have a simple routine which utilizes an Ajax to query database for keywords presence in database and returns matched records count. Below is the code for 2 pages. First page would take an input, post to the second via ajax and displays the returned message.
Everything works fine when I use keywords contained Latin characters. The problem is, that when I try Cyrillic strings, no match is found via ajax although it would work by directly posting to the page2 from page1 via “Submit” button. Cyrillic data in db is encoded as Windows-1251.
I have not worked much with multilingual support in the past. Now I wonder how to make this to work. The data posted via xmlHttp is converted to Unicode. What should I do to properly decode posted data at second page before issuing an sql query?


<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">

<form method="post" action="page2.asp">
<input type="text" id="T1" name="T1" size="20">
<input type="submit" value="Submit" name="B1">
<input type="button" value="Ajax" name="B2" onclick="ajaxOptions('T1='+document.getElementById ('T1').value,'ret','page2.asp');">
<div id="ret">&nbsp;</div>

<script language="javascript">
var xmlHttpObj, LayerID
function ajaxOptions(strArgs,divID,page){
if (xmlHttpObj==null){
document.getElementById(LayerID).innerHTML="Ajax is not supported";
var asURL=page;
xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=Windows-1251");


function checkState() {
if (xmlHttpObj.readyState==4){
document.getElementById(LayerID).innerHTML=xmlHttp Obj.responseText;

function BindXmlHttp(){
var xmlHttpObj=null;
xmlHttpObj=new XMLHttpRequest();
catch (err)
xmlHttpObj=new ActiveXObject("Msxml2.XMLHTTP");
catch (err)
xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttpObj;



<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">

testKey = Request.Form("T1")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strConn = strConn & Server.MapPath("test.mdb") & ";"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open strConn

str_sql = "SELECT Count(*) FROM tblkey WHERE testkey = '" & testKey & "';"
result_count = objConn.Execute(str_sql)(0)

Response.Write "Found " & result_count & " records"

Set objConn = Nothing
Apr 24 '07 #1
0 2375

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by steve | last post: by
reply views Thread by buran | last post: by
25 posts views Thread by marcin.rzeznicki | last post: by
7 posts views Thread by Dormilich | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.