.get 响应的字符编码问题
据我了解,当 BOM 字符不匹配时,会生成  字符串。我在 jQuery .get() 调用的响应开始时得到它们。目前,我正在修改响应并删除字符,但我想了解为什么会发生这种情况。
现有网站包含元标记:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
并且我尝试在标题标记之前添加 header:
header('Content-Type: text/html; charset=utf-8');
,无论是单独添加还是与元标记结合使用。无论这些标记是否存在,Firefox 都会报告该页面具有 UTF-8 编码。我尝试将 .get() 调用替换为指定编码的 .ajax() 调用,但无济于事:
$.ajax(
{
type:'GET',
url: 'common/includes/FilterDataLog.cfm',
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
data: 'column='+selectedValue+'&filterValue='+filterValue+'&filterID='+filterID+'&configFile=log/log.xml',
success: function(response){
//response = response.replace('', '');
thisTextFilter.replaceWith(response);
}
});
FilterDataLog.cfm 页面返回:
<div id="" class="fl txt_input_container">
<input type="text" class="txtvalueFilter" id="myFilterID" name="txtvalueFilter" value="#url.filterValue#"/>
</div>
<script>
$(document).ready(function(){
$('#myFilterID').autocomplete({
delay: 500,
source: function(request, response) {
$.ajax({
url: "cfc/autoSuggestLog.cfc?method=lookupSomething&returnformat=json",
dataType: "json",
data: {
search: request.term,
maxRows: 30
},
success: function(data) {
response(data);
}
})
},
change: function(event, ui) {
if (!ui.item) {
$(this).val('');
}
}
});
});
</script>
我在站点中找不到设置字符编码的其他位置,所以我很难过。有什么想法吗?
I understand that the  character string is generated when there's a BOM character mismatch. I'm getting them at the beginning of a response from a jQuery .get() call. For the time being, I'm hacking the response and stripping out the characters, but I'd like to understand why this is happening.
The existing site includes the meta tag:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
and I've tried adding the header:
header('Content-Type: text/html; charset=utf-8');
before the title tag, both by itself and in conjunction with the meta tag. Regardless of whether either of these tags exists, Firefox reports that the page has UTF-8 encoding. I've tried replacing the .get() call with an .ajax() call that specifies the encoding, to no avail:
$.ajax(
{
type:'GET',
url: 'common/includes/FilterDataLog.cfm',
contentType: "application/x-www-form-urlencoded;charset=UTF-8",
data: 'column='+selectedValue+'&filterValue='+filterValue+'&filterID='+filterID+'&configFile=log/log.xml',
success: function(response){
//response = response.replace('', '');
thisTextFilter.replaceWith(response);
}
});
The FilterDataLog.cfm page returns:
<div id="" class="fl txt_input_container">
<input type="text" class="txtvalueFilter" id="myFilterID" name="txtvalueFilter" value="#url.filterValue#"/>
</div>
<script>
$(document).ready(function(){
$('#myFilterID').autocomplete({
delay: 500,
source: function(request, response) {
$.ajax({
url: "cfc/autoSuggestLog.cfc?method=lookupSomething&returnformat=json",
dataType: "json",
data: {
search: request.term,
maxRows: 30
},
success: function(data) {
response(data);
}
})
},
change: function(event, ui) {
if (!ui.item) {
$(this).val('');
}
}
});
});
</script>
I've found no other places in the site where character encoding is being set, so am stumped. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一些事情需要检查。
There are a few things to check here.
<cfprocessingdirective pageencoding="utf-8"/>
为了确定问题是否源自 IDE,我会将代码复制并粘贴到文本编辑器(例如 NotePad++)中。然后您可以在此处选择编码>转换为无 BOM 的 UTF-8,然后保存并重新运行该文件。如果错误没有发生,那么您需要更改 IDE 中的设置。
您没有提到您的服务器,您是否正在运行 ColdFusion 的独立副本?或者是通过 IIS、Apache Tomcat、Apache HTTPD 运行?其中任何一项都可能是 BOM 插入的来源。
To determine if the issue is originating from the IDE I would copy and paste your code into a text editor such as NotePad++. There you can then select Encoding > Convert to UTF-8 without BOM, then save and re-run the file. If the error doesn't occur then you have a setting in your IDE to change.
You don't mention your servers, are you running a standalone copy of ColdFusion? Or is it running through IIS, Apache Tomcat, Apache HTTPD? Any one of those could be the source of the BOM insertion.