473,372 Members | 1,095 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,372 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 2435

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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.