Accentuation with Multipart/form-data form and sql server using ajax

Asked

Viewed 319 times

0

Hello. I have a problem that’s keeping me up at night. I am working on legacy code in classic Asp and need to register a form that contains pdf file and data (such as name, surname) and other fields. When the page is submitted to the server (iis8) through the form Submit event, everything goes well and the fields are saved in sql with the accents correctly. However, some files are large and the response of the page may take a while, leaving the user unaware of what is happening. I started using ajax to do Submit and keep a progress bar. The problem is that accentuation is not correctly persisted in the database. I already checked the save.Asp page in the firefox debug and the accent is correct. I re-sponse.write the values of the fields and everything is accented correctly. The two files (register.Asp and save.Asp) have the same encoding (Windows-1252). I realized that "content-length" when posted by ajax has 24 bytes more than when only posted with Submit. How do I resolve this situation? Has anyone gone through this? I am using the jQuery Form Plugin component (malsup dot com jquery form) to submit the form via ajax.

Edit

Looks like this is an ADODB problem. I tested several ways to submit the data to the database, all using ADODB (with command, recordset, etc). In all cases when I use ajax (no matter the ajax plugin to do this - tested with pure ajax, jQuery Form Plugin and jQuery File Upload Plugin) the ADODB encodes the text that contains accented characters before uploading to the database. But this only happens with an ajax Submit. When Submit is the default, nothing is hidden and everything goes well. To solve the problem, I used a function found here: https://support.persits.com/show.asp?code=PS130806188 and everything is working as it should. To simplify the answer: The.Asp registration file is saved in utf-8. The file save.Asp has the first line like this:e <%@LANGUAGE="VBSCRIPT" CODEPAGE=1252%> and saved in "Western European (Windows) - Codepage 1252". Yeah, it’s weird, but it’s working fine. The function of Encode/Decode was thus:

Function Utf8ToUnicode(strText)
    With CreateObject("ADODB.Stream")
        .Open
        .Charset = "Windows-1252"
        .WriteText strText
        .Position = 0
        .Type = 2 ' adTypeText
        .Charset = "utf-8"
        Utf8ToUnicode = .ReadText(-1) 'adReadAll
        .Close
    End With
End Function

Before submitting a field that can contain special characters, I pass the value that came from the registration page to the function:

dim nome
nome = Utf8ToUnicode(request("txtNome"))
  • The save.Asp page has the tag "<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>" before the rest of the code?

  • Hi, Renato. The codepage for this page is 1252, which is the code page for accented characters. Yes, it’s in the first row of both files.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.