0
I have a function that makes an ajax call, and sends the data to be saved in the database, the problem is that whenever you save a word that has some special character or accent, it does not encode in the correct way,
I’ve tried using the :
encodeURIComponent(string)
pórem did not show the result experienced, my function is as follows
function relatorio() {
var tipo = document.getElementById('tipo').value;
$.ajax({
method: "POST",
url: "relatorio.asp",
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
data: {
tipo: encodeURIComponent(tipo) , exs: "relatorio_tipo"
}
});
}
if I send a type = "function" saved on the seat as follows = "fun&231&227o"
I don’t know if I’m doing it right or if I’m missing something would like to know a solution so that my variable is saved in the correct way.
code that is in the report.
if ex = "relatorio_tipo" then
Response.Charset="ISO-8859-1"
tipo= trata_sql(request("tipo"))
set rs = Server.CreateObject("ADODB.Recordset")
rs.LockType = 2
rs.Open "relatorios", conexao
rs.addnew
rs("tipo") = tipo
rs("data") = now()
rs.Update
rs.close
set rs = nothing
conexao.close
set conexao = nothing
end if
Which database is it? It may be the encoding of the databank that is not accepting special characters Or try to pass this charset to iso 'Content-type: text/html; charset=iso-8859-1'
– D Wojcik
the database is mysql, I realized that in the date:{ type: encodeURIComponent(type)} the variable does not encode, when I give a print to see what it brings does not return in the correct way, I tried to use Content-type: text/html; charset=iso-8859-1 and the problem is still continuing and the type is equal = fun%C3%A7%C3%A3o
– Jess
It may be that the problem is in the same bank, you can take the encoded string and do a direct Insert in the table to see if it is saved correctly?
– André