Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving a £ sign to access db via AJAX post

Status
Not open for further replies.

emozley

Technical User
Jan 14, 2003
769
GB
Hi there,

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
 
Make sure your database, table, column is all utf8, you may need to encode the ajax... if you are using jquery it should be done for you... but I would say this has something to do with utf8 ... You also may consider converting it to
Code:
&pound or &#163;

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top