以下jQuery ajax函数运行PHP脚本,该脚本查询包含编码为UTF-8的条目的MySQL数据库:
The following jQuery ajax function runs a PHP script that queries a MySQL database containing entries that are encoded as UTF-8:
function searchLocations() { var stateSelected = $("#stateSelect").val(); $.ajax({ url: 'ajax/json.php', dataType: 'json', data: 'state='+stateSelected, success: function(data) { placeMarkers(data.markerdata.markers); } }); }返回到函数的JSON对象包含经度和纬度
The JSON object returned to the function contains the longitudes and latitudes of map marker objects as well as a name to display in an info window when each marker is clicked.
每个名称加载正常,并且显示没有问题,除了一个地图标记对象。单个名称,其中包含字符ñ。此名称在JSON对象中作为null返回。
Every name loads fine, and is displayed without a problem except for a single name which contains the character "ñ". This name is returned in the JSON object as "null". How can I make this name display properly?
推荐答案我以前遇到这个问题,我发现有两个选项:
I used to have this problem and I found there was two options:
如果没有这些选项,可能值得看看字符集由您的网页使用。尝试并使用UTF-8编码你的HTML,看看是否有帮助。
Failing both those options it may be worth looking at the character set used by your page. Try and use UTF-8 to encode your HTML and see if that helps.
如果你使用了一个基本的PHP页面查询有问题的数据和没有使用jQuery和AJAX,打印出名称,但它仍然无法正确显示。如果不是,它也可能是MySQL的字符集问题。
Without using jQuery and AJAX if you did a basic PHP page that queried the data in question and prints the name out does it still not display correctly. If it doesn't it could also be a character set issue with MySQL.
希望任何这些指针帮助。让我知道你是怎么来的。
Hope any of these pointers help. Let me know how you get on.
更多推荐
特殊字符断点json返回jQuery
发布评论