.get 响应的字符编码问题

发布于 2024-12-12 02:24:12 字数 2026 浏览 0 评论 0原文

据我了解,当 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

佞臣 2024-12-19 02:24:12

这里有一些事情需要检查。

  1. 首先,确保您的 IDE 正确保存 .cfm/.cfc 文件。如果您使用基于 Eclipse 的编辑器,例如 CFBuilder、CFEclipse 或其他一些 Eclipse 插件,您可以单击 Window >首选项,然后导航至常规>工作区。确保您的文本文件编码为“UTF-8”。我有一种感觉,这是你的问题。如果您没有使用更流行的 ColdFusion 编辑器之一,则需要查阅您自己的 IDE 帮助文件。完成后,重新保存文件并重试。
  2. 如果第一步未能解决问题,请尝试在 CFC 的开头放置一个:

There are a few things to check here.

  1. First, make sure your IDE is saving your .cfm/.cfc files correctly. If you are using an Eclipse based editor such as CFBuilder, CFEclipse or some other plugin for Eclipse you can click Window > Preferences and then navigate to General > Workspace. Make sure your text file encoding is 'UTF-8'. I have a feeling this is your issue. If you are not using one of the more popular ColdFusion editors you'll need to consult with your own IDE help files. Once complete, re-save your file(s) and try again.
  2. If step one did not fix the issue, try placing a at the head of your CFC: <cfprocessingdirective pageencoding="utf-8"/>
拒绝两难 2024-12-19 02:24:12

为了确定问题是否源自 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文