问题描述
我想从另一个域(CORS)读取json数据文件.此文件包含Unicode数据,例如:
I want to read json data file from another domain (CORS).This file contain Unicode data, Like:
{"id":21,"name":"پرسپولیس تهران"}
我使用了像这样的JQuery Ajax函数:
I used JQuery Ajax function like this:
$.ajax({
type: "GET",
cache: false,
url: SDomain + 'XML/TeamXMLCache/' + filename + '.json',
dataType: "json",
contentType: 'application/json; charset=UTF-8',
success: parseXml,
error: function (request, status, errorThrown) {
console.log(request);
console.log(status);
console.log(errorThrown);
}
});
这在Chrome 39中可以正常运行,但在IE11和amp;中无法正常工作FF32.
And this work me fine in Chrome 39 but not working in IE11 & FF32.
在IE中,我收到 parsererror 错误.
In IE I get parsererror error.
有关更多信息:
- responseText是:
{"id":21,"name":〜13〜HD3 * G1'F"}
- readyState:4
- statusText:确定"
- 状态:200
最后我的配置文件是:
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
所以请告诉我为什么?我不是初学者!
So please tell me why? I'm not a beginner!
实际示例是:我的真实样本
推荐答案
当我加载 http://static.persiangulfcup.org/XML/TeamXMLCache/21-%D9%BE%D8%B1%D8%B3%D9%BE%D9%88%D9%84%DB%使用Firefox在浏览器窗口中显示8C%D8%B3-%D8%AA%D9%87%D8%B1%D8%A7%D9%86.json?_ = 1417448329770 在文档信息中,编码为UTF-16LE,而不是您的帖子中所示的UTF-8.基于此,我认为您需要确保数据已正确地以UTF-8编码,或者您需要确保将其与指示实际编码的内容类型标头一起提供.
When I loaded http://static.persiangulfcup.org/XML/TeamXMLCache/21-%D9%BE%D8%B1%D8%B3%D9%BE%D9%88%D9%84%DB%8C%D8%B3-%D8%AA%D9%87%D8%B1%D8%A7%D9%86.json?_=1417448329770 with Firefox in a browser window, it displayed the JSON fine but indicated in document info that the encoding is UTF-16LE and not UTF-8 as indicated in your post. Based on that I think you need to make sure the data is correctly UTF-8 encoded or you need to make sure it is served with a content type header indicating the real encoding.
这篇关于阅读与解析unicode json数据在IE和FF中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!