Hi there,
I have a form:
and I have some AJAX code:
and I have some server side code written in ASP
For some strange reason when I enter some data and try to save it £ signs get saved into the database as £ not £.
I have echoed the SQL query that is being run and there is no sign of the strange symbol.
Also if I run an ASP script that executes the same command the £ goes into the database normally. It only appears when passed via an AJAX request.
Any ideas? I am writing to an access database. I have noticed the problem does not occur if I write to a MS SQL database.
Thanks very much
Ed
I have a form:
Code:
<form name="myform">
<input type="text" id="TheText">
<input type="button" onclick="saveData(encodeURIComponent(getElementById('TheText').value));" value="Go">
</form>
and I have some AJAX code:
Code:
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
function saveData(TheText)
{
xmlhttpSaveData=GetXmlHttpObject();
if (xmlhttpSaveData==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
xmlhttpSaveData.open("POST","savedata.asp",true);
xmlhttpSaveData.setRequestHeader("Content-type","application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
xmlhttpSaveData.onreadystatechange=function(){if (xmlhttpSaveData.readyState==4){var aspResponse = xmlhttpSaveData.responseText;document.getElementById('info').innerHTML = aspResponse; }};
xmlhttpSaveData.send("TheText="+TheText+"&sid="+Math.random());
}
and I have some server side code written in ASP
Code:
<%
Set DB = Server.CreateObject("ADODB.Connection")
Set TBL = Server.CreateObject("ADODB.RecordSet")
DB.Mode = adModeReadWrite
DB.Open "DSN=docbundle"
TheText=Request.Form("TheText")
strSQL = "INSERT INTO TestTable(TheText) VALUES ('" & Replace(TheText, "'", "''") & "')"
Response.Write(strSQL) & "<br>"
TBL.Open strSQL, DB
DB.Close
Set TBL=Nothing
Set DB=Nothing
%>
For some strange reason when I enter some data and try to save it £ signs get saved into the database as £ not £.
I have echoed the SQL query that is being run and there is no sign of the strange symbol.
Also if I run an ASP script that executes the same command the £ goes into the database normally. It only appears when passed via an AJAX request.
Any ideas? I am writing to an access database. I have noticed the problem does not occur if I write to a MS SQL database.
Thanks very much
Ed