【发布时间】:2014-05-07 15:10:55
【问题描述】:
我正在使用一个相当简单和标准的 jQuery post 将数据发布到另一个页面。两个页面都有
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<% Response.CharSet = "UTF-8" %>
jQuery 帖子的函数部分只有alert(data),而我返回的只是用括号括起来的一个表单字段的值。因此,当我添加英镑符号 (£) 时,它会相应地提醒 [£]
但是,我也在我发布到的页面上写入了一个文本文件,它实际上写入了£ 而不仅仅是£
所以当我进行数据库插入时,它实际上也插入了£ 而不仅仅是£
发生这种情况的任何原因?
第 1 页
<!DOCTYPE html>
<html lang="en">
<head>
<title>Intelligence Point </title>
<meta name="description" content="">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="">
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/css/custom.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css"> p,textarea {
padding: 5px;
}
textarea {
border:1px solid #ccc;}
</style>
</head>
<body>
<div class="container" style="margin-top:-30px;">
<p> </p>
<p class="bg-primary">Comments last updated by JJ004 on 2014-05-07 at 16:28</p>
<p><textarea class="bg-success" maxlength="4000" style="width:100%;" rows="4" wrap="soft" id="comment1">£</textarea></p>
<p><textarea class="bg-success" maxlength="4000" style="width:100%;" rows="4" wrap="soft" id="comment2">£</textarea></p>
<p><textarea class="bg-success" maxlength="4000" style="width:100%;" rows="4" wrap="soft" id="comment3">£</textarea></p>
<p><textarea class="bg-success" maxlength="4000" style="width:100%;" rows="4" wrap="soft" id="comment4">£</textarea></p>
<button type="button" class="btn btn-success" id="postcomment">Save comments</button>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
window.resizeTo(800, 750);
$("#postcomment").click(function () {
$.post(
"putComment.asp",
{
yR: "123",
yP: "456",
yN: "",
yF1: "XXX",
yF2: "YYY",
yF3: "ZZZ",
yF4: "",
yC1: $('#comment1').val(),
yC2: $('#comment2').val(),
yC3: $('#comment3').val(),
yC4: $('#comment4').val()
},
function (data) {
//alert(data);
var url = "SOMEWHERE.COM";
alert("Narrative saved");
window.opener.location.href = url;
window.close(); // or self.close();
}
);
});
});
</script>
</body>
</html>
putComment.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>
【问题讨论】:
-
这个已经在本站处理过多次了,你可能会觉得this answer我给的有用。
-
该字符似乎被插入到 SQL 之前。 nvarchar 和 2012 @Lankymart - 不适合我,仍然不起作用
-
@marc_s OP 说它在进入数据库之前已经不匹配的编码。问题很可能是他们的页面没有保存为
UTF-8。 -
@pee2pee 我保证它会起作用,我一次又一次地听到 “它不起作用” 关于这个确切的问题,最终它总是会起作用。您能否更新您的问题并显示您尝试过的代码,我会帮助您解决它。 Another link OP 承认他们缺少一些东西。
-
编辑 - 我很可能错过了一些东西。透过树林看不到树林……
标签: jquery asp-classic character-encoding jquery-post