This is my ASP webservice that queries the db and provides a Json file/object:
<!--#include file="JSON_2.0.4.asp"-->
<!--#include file="JSON_UTIL_0.1.1.asp"-->
<%
Response.CodePage = 28591
Response.CharSet = "ISO-8859-1"
'response.write("ç ã â é À á") -> characters are written correctly with or without the two lines above but not the json feed
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.Open "Provider=sqloledb;SERVER=localhost;DATABASE=DB;UID=user;PWD=PASS;"
QueryToJSON(Connection,"select field1, field2, field3, field4, FROM table").flush
%>
The response text:
[{“col1″:”value1″,”col2″:”value1″,”col3″:”value1”},
{“col1″:”value2″,”col2″:”value2″,”col3″:”value2”},
{“col1″:”value3″,”col2″:”value3″,”col3″:”value3”}]
The response json is not properly encoded replacing punctuation marks “\u00E9” and adding a lot of spaces in the middle and in the end of the values.
When I open this file directly in the browser it looks ok in exception of the replaced characters, but when I feed it as a xmlhttp.responseText to the IndexedDB it appears in the console.log with a lot of spaces and line breaks throwing a “DataError: Data provided to an operation does not meet requirements.” error.
I think the spaces and line breaks might be cause by the replaced characters, something like this “\n”
Update:
I’ve tried using "xhr.setRequestHeader( "Content-Type", "application/json", "Charset=ISO-8859-1");" in my ajax request but it’s not working either
Just figured it out!
The query to the DB was retrieving the fields with spaces at the end that were being somehow incremented as the program ran, just changed the query line to:
Now the response is clean and already accepting the correct charset.