jQuery、经典ASP和sqlserver-Â;在£之前插入;
我正在使用一个相当简单和标准的jQuery post将数据发布到另一个页面。两页都有jQuery、经典ASP和sqlserver-Â;在£之前插入;,jquery,asp-classic,character-encoding,jquery-post,Jquery,Asp Classic,Character Encoding,Jquery Post,我正在使用一个相当简单和标准的jQuery post将数据发布到另一个页面。两页都有 <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <% Response.CharSet = "UTF-8" %> putcoment.asp <!DOCTYPE html> <html lang="en"> <h
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<% Response.CharSet = "UTF-8" %>
putcoment.asp
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<% Response.CharSet = "UTF-8" %>
</head>
<body>
<!--#include virtual="/comments/connProd.inc"-->
<%
Function cleanSQL(thisWord)
Dim newWord
If thisWord <> "" Then
newWord = Replace(thisWord,"/*","")
newWord = Replace(newWord,"*/","")
newWord = Replace(newWord,"UNION","")
newWord = Replace(newWord,"'","''")
newWord = Replace(newWord,"""","&quot;")
newWord = Replace(newWord,"<script>","[script]")
newWord = Trim(newWord)
End If
cleanSQL = newWord
End Function
Function in_array(element, arr)
For i=0 To Ubound(arr)
If Trim(arr(i)) = Trim(element) Then
in_array = True
Exit Function
Else
in_array = False
End If
Next
End Function
zR=cleanSQL(request.form("yR"))
zP=cleanSQL(request.form("yP"))
zN=cleanSQL(request.form("yN"))
zC1=cleanSQL(request.form("yC1"))
zC2=cleanSQL(request.form("yC2"))
zC3=cleanSQL(request.form("yC3"))
zC4=cleanSQL(request.form("yC4"))
zF1=cleanSQL(request.form("yF1"))
zF2=cleanSQL(request.form("yF2"))
zF3=cleanSQL(request.form("yF3"))
zF4=cleanSQL(request.form("yF4"))
'response.Write "["&zC1 & "]<br/>"
sql="insert into IPPR.Comments values("
sql=sql+"'"+zR+"',"
sql=sql+"'"+zP+"',"
sql=sql+"'"+zF1+"',"
sql=sql+"'"+zF2+"',"
sql=sql+"'"+zF3+"',"
sql=sql+"'"+zF4+"',"
sql=sql+"'"+zC1+"',"
sql=sql+"'"+zC2+"',"
sql=sql+"'"+zC3+"',"
sql=sql+"'"+zC4+"',"
sql=sql+"getdate(),"
sql=sql+"'"+zN+"')"
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile("c:\inetpub\wwwroot\text\log.txt",8,true)
f.WriteLine("")
f.WriteLine("["&zC1 & "]" & sql)
f.close
set f=nothing
set fs=nothing
'response.write sql
'response.flush
set rs=conn.execute(sql)
%>
</body>
</html>
注意:
这是真的很难传达代码,所以我写这个
正如我已经解释过的,由于缺少关键步骤,编码不匹配,请尝试以下方法
将以下行添加到第1页和putComments.asp的开头
- 第一行告诉IIS将页面内容处理为
UTF-8
- 第二行指示所有
响应
字符串编码为UTF-8
- 第三行相当于设置
;内容类型标题中的字符集=UTF-8
确保链中的所有ASP文件(包括任何#include
文件)都是使用UTF-8
编码保存的,否则IIS在不使用时将文件作为UTF-8
处理将导致编码不匹配
任何发布的数据都应该以UTF-8
的形式发送,这取决于您使用JQuery Ajax发布的机制(默认情况下使用UTF-8
),因此此处不需要更改
有用的链接
加上这个就好了 这个问题在这个网站上已经处理过多次了,你可能会发现我给出的答案很有用。这个字符似乎是在SQL之前插入的。nvarchar和2012@Lankymart-我不行,现在仍然不行work@marc_sOP说在它进入数据库之前,它的编码已经不匹配了。问题很可能是他们的页面没有保存为UTF-8
@pee2pee我保证它会工作的,我一次又一次听到关于这个确切问题的“它不工作”,最后总是这样。你能更新你的问题并展示你尝试过的代码吗?我会帮你解决它。OP承认他们遗漏了什么。编辑-我很可能遗漏了什么。透过树木看不见森林…明天我会用新鲜的眼光去尝试。这是十多年来编写经典ASP的第一次,自从jQuery问世以来,我遇到了很多这样的问题!任何被引用的CSS和JS文件如何?Response.ContentType=“text/html”Response.AddHeader“Content-Type”、“text/html;charset=UTF-8”Response.CodePage=65001 Response.charset=“UTF-8”@pee2pee CSS和JS文件应该不重要——ASP返回的html是如何编码的。有时,最好的办法就是暂时离开并重新开始。我如何知道我的文件保存为哪个代码页?@IanWarburton取决于您使用的是什么,如果您使用Visual Studio编辑文件,您可以使用高级保存选项
命令(默认情况下不显示)进行检查。自定义菜单栏以添加它,您可以在文件
菜单命令下找到它。正如我已经解释的响应。字符集
与设置相同;Response.AddHeader(“内容类型”)中的字符集
,
同样Response.ContentType=“text/html”
与设置Response.AddHeader(“内容类型”)相同,"text/html
。那一行完全不相关,那么这与我的答案有什么不同呢?我告诉过你它会起作用。我只是在所有有问题的文件中添加了前两行,它就起作用了。我把它们拿出来,它就停止了作用。我把每一行都放进去,它就不起作用了。我把它们都放回去,它就起作用了。同时,我感谢你的帮助和帮助指南,这两行是拼图的最后一部分-我发现这两条语句与Response.AddHeader(“Content-Type”,“text/html;charset=UTF-8”)相同,因此非常奇怪
,但你现在是第二个这样做的人。我必须研究一下,但是在我用经典ASP处理编码的这些年里,我从来没有遇到过这个问题。如果你使用过,
字符,这确实是我10年来第一次遇到编码问题-从ASP、ColdFusion、PHP等作为一个字符串分隔符,您以前可能遇到过它,这是一个真正的难题。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<% Response.CharSet = "UTF-8" %>
</head>
<body>
<!--#include virtual="/comments/connProd.inc"-->
<%
Function cleanSQL(thisWord)
Dim newWord
If thisWord <> "" Then
newWord = Replace(thisWord,"/*","")
newWord = Replace(newWord,"*/","")
newWord = Replace(newWord,"UNION","")
newWord = Replace(newWord,"'","''")
newWord = Replace(newWord,"""","&quot;")
newWord = Replace(newWord,"<script>","[script]")
newWord = Trim(newWord)
End If
cleanSQL = newWord
End Function
Function in_array(element, arr)
For i=0 To Ubound(arr)
If Trim(arr(i)) = Trim(element) Then
in_array = True
Exit Function
Else
in_array = False
End If
Next
End Function
zR=cleanSQL(request.form("yR"))
zP=cleanSQL(request.form("yP"))
zN=cleanSQL(request.form("yN"))
zC1=cleanSQL(request.form("yC1"))
zC2=cleanSQL(request.form("yC2"))
zC3=cleanSQL(request.form("yC3"))
zC4=cleanSQL(request.form("yC4"))
zF1=cleanSQL(request.form("yF1"))
zF2=cleanSQL(request.form("yF2"))
zF3=cleanSQL(request.form("yF3"))
zF4=cleanSQL(request.form("yF4"))
'response.Write "["&zC1 & "]<br/>"
sql="insert into IPPR.Comments values("
sql=sql+"'"+zR+"',"
sql=sql+"'"+zP+"',"
sql=sql+"'"+zF1+"',"
sql=sql+"'"+zF2+"',"
sql=sql+"'"+zF3+"',"
sql=sql+"'"+zF4+"',"
sql=sql+"'"+zC1+"',"
sql=sql+"'"+zC2+"',"
sql=sql+"'"+zC3+"',"
sql=sql+"'"+zC4+"',"
sql=sql+"getdate(),"
sql=sql+"'"+zN+"')"
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile("c:\inetpub\wwwroot\text\log.txt",8,true)
f.WriteLine("")
f.WriteLine("["&zC1 & "]" & sql)
f.close
set f=nothing
set fs=nothing
'response.write sql
'response.flush
set rs=conn.execute(sql)
%>
</body>
</html>
Response.ContentType = "text/html"
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.CodePage = 65001
Response.CharSet = "UTF-8"