地名异常
我正在使用 Geonames 网络服务在我的网站上注册。如果发生错误,我想给自己发送一封包含错误的电子邮件。 Geonames 返回异常 http://www.geonames.org/export/webservice-exception.html< /a> 但我不知道如何显示它们。
我在 Jquery 中使用 Geonames 在用户输入位置时自动完成位置。
$( "#location" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
q: request.term,
featureClass: "P",
style: "full",
maxRows: 10
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name,
latitude: item.lat,
longitude: item.lng,
status: item.status
}
}));
在 success 函数中,最后一个参数 status 应返回请求的状态。我将其附加到 div 但没有出现。请帮助我..我不确定我做错了什么。
I am using Geonames web service for registration on my website. If an error occurs I want to send myself an email with the error. Geonames returns exceptions http://www.geonames.org/export/webservice-exception.html but I'm not sure how to display them.
I'm using Geonames in Jquery for auto-completing locations when users enter them.
$( "#location" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
q: request.term,
featureClass: "P",
style: "full",
maxRows: 10
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name,
latitude: item.lat,
longitude: item.lng,
status: item.status
}
}));
In the success function the last parameter status should return the status of the request. I appended that to a div but nothing appears. Please help me.. I'm not sure what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对这个问题进行了相当多的研究,我认为你想得太多了。在我看来,您的 JSON 响应将包含
status
属性的唯一情况是当 HTTP 响应不是 200 时。例如,当您从服务服务器获取 503 时由于过载,该成功函数永远不会真正运行。据我所知,您似乎需要添加
error: function( data ) {...}
才能访问status
选项。希望这有帮助!I played around quite a bit with this one and I think you're overthinking it. It looks to me like the only situation in which your JSON response is going to contain a
status
attribute is when the HTTP response is not 200.For example, when you get a 503 from the server for the service being overloaded, that success function never actually gets run. From what I can tell it looks like you will need to add
error: function( data ) {...}
to be able to access thestatus
option. Hope that was helpful!