473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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?

page1.asp
[HTML]

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

<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>
</form>

<script language="javascript">
<!--
var xmlHttpObj, LayerID
function ajaxOptions(strArgs,divID,page){
LayerID=divID;
xmlHttpObj=BindXmlHttp();
if (xmlHttpObj==null){
document.getElementById(LayerID).innerHTML="Ajax is not supported";
return;
}
var asURL=page;
asURL=asURL+"?rnd="+Math.random();
xmlHttpObj.onreadystatechange=checkState;
xmlHttpObj.open("POST",asURL,true);
xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=Windows-1251");
xmlHttpObj.send(strArgs);

}

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

function BindXmlHttp(){
var xmlHttpObj=null;
try{
xmlHttpObj=new XMLHttpRequest();
}
catch (err)
{
try{
xmlHttpObj=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (err)
{
xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttpObj;
}
//-->
</script>

</body>
</html>

[/HTML]

page2.asp
[HTML]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>
<%

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.Clear
Response.Write "Found " & result_count & " records"

objConn.Close
Set objConn = Nothing
%>
[/HTML]
Apr 24 '07 #1
0 2437

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

Similar topics

14
by: Kevin Knorpp | last post by:
Hello. I need to be able to extract the data from the attached file (or any file in the same format) so that I can work with the data in PHP. I'm fairly comfortable with using PHP with...
3
by: steve | last post by:
Hi, I am opening a stream that is UTF encoded. I use fgetc to read the stream- which is binary safe. I add every character read to a string. But when I look at the stream, I see some...
40
by: Peter Row | last post by:
Hi all, Here is my problem: I have a SQL Server 2000 DB with various NVarChar, NText fields in its tables. For some stupid reason the data was inserted into these fields in UTF8 encoding. ...
0
by: Johann Blake | last post by:
In my need to decode a JPEG 2000 file, I discovered like many that there was no functionality for this in the .NET Framework. Instead of forking out a pile of cash to do this, I came up with the...
0
by: buran | last post by:
Dear ASP.NET Programmers, I am saving the contents of a file to the database using HttpWebRequest and HttpWebResponse classes. I am also posting some data to the requested page. What I cannot...
4
by: SSS | last post by:
Hello there, My problem is that I have a page which is displaying 4 real time data values which are being refreshed every one minute. On the same page I have other text boxes where user enters...
25
by: marcin.rzeznicki | last post by:
Hello everyone I've got a little problem with choosing the best decoding strategy for some nasty problem. I have to deal with very large files wich contain text encoded with various encodings....
7
Dormilich
by: Dormilich | last post by:
Hi, I've got a very strange problem with UTF-8 encoded data outside ASCII range. While on localhost all went smoothly, the same pages on the server show � (Latin-1 chars (ä, ö, ü, ß, ...)) and...
3
by: mviuk | last post by:
Hi, I'm looking for a system which detaches the decoding process from the encoding process. That is, I would like a system for encoding data, but even if both the encoded data and the encoding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.