最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - HTML encoding ° degree symbol extra space - Stack Overflow

programmeradmin1浏览0评论
  1. <div id="a">°F</div>
  2. $.get("",{'TU':$('#a').text()});
  3. IIS server logs show the following params:
    99.5% of the time: TU=%C2%B0F
    0.5% of the time: TU=%C2%B0+F
  4. server subsequently crashes because it doesn't know what '° F' is. Admittedly one of the flaws is that we are scraping text out of the DOM & sending it to our server. This is where I suspect the problem is, but I would like to understand more.

Other info: the 0.5% of the time has been both IE8 & Chrome. All IP's geolocated to Columbia, which makes it seem like a local issue, but we've been unable to replicate it.

Ideas??

  1. <div id="a">°F</div>
  2. $.get("http://blah./go",{'TU':$('#a').text()});
  3. IIS server logs show the following params:
    99.5% of the time: TU=%C2%B0F
    0.5% of the time: TU=%C2%B0+F
  4. server subsequently crashes because it doesn't know what '° F' is. Admittedly one of the flaws is that we are scraping text out of the DOM & sending it to our server. This is where I suspect the problem is, but I would like to understand more.

Other info: the 0.5% of the time has been both IE8 & Chrome. All IP's geolocated to Columbia, which makes it seem like a local issue, but we've been unable to replicate it.

Ideas??

Share Improve this question edited Sep 27, 2010 at 22:55 Greg 23.4k11 gold badges60 silver badges80 bronze badges asked Sep 27, 2010 at 22:52 ZacZac 3,2854 gold badges28 silver badges30 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 1

So the problem is that sometimes there is a space between the ° and the F, that space gets translated into a +, and the server doesn't accept it? If so, why not strip out the space before sending it?

$.get("http://blah./go",{'TU':$('#a').text().replace(' ', '')});
// Or a more granular fix
$.get("http://blah./go",{'TU':$('#a').text().replace(/°\sF/, '°F')});

How is the text being put into the div? You should output that before checking the server value. I don't think it's likely that you're getting a different encoding of the same text. It's probably something to do with how you're putting it into the page.

Also try setting the page encoding on the server before you get the query string, it could be that different browsers are using a different encoding. UTF-8 is the encoding suggested by w3. In Java, you have to make sure you set the encoding before any calls to read anything from the client.

发布评论

评论列表(0)

  1. 暂无评论