简体   繁体   English

jQuery $ .ajax在Safari中剥离JSON对象属性

[英]jQuery $.ajax stripping out JSON object properties in Safari

I am using the following code: 我正在使用以下代码:

$.ajax( {
    url: "http://www.earthquakescanada.nrcan.gc.ca/api/earthquakes/latest/7d.json",
    dataType: 'json',       
    success: successHandler
} );

var successHandler = function ( data ) {
    console.log( data );
}

For some reason and only in Safari, the "location" property for the objects returned are stripped out. 由于某些原因,并且仅在Safari中,删除了返回对象的“位置”属性。 Can anyone explain why and suggest a solution? 谁能解释原因并提出解决方案?

It's not a jQuery or $.ajax problem, but the json resource you are trying to get, has a kind of user agent controller. 这不是jQuery$ .ajax问题,但是您尝试获取的json资源具有一种用户代理控制器。

Try to open the url in Chrome and then in Safari, you will see two different json files from the same url http://www.earthquakescanada.nrcan.gc.ca/api/earthquakes/latest/7d.json 尝试在Chrome中打开url,然后在Safari中打开,您将看到来自同一url的两个不同的json文件http://www.earthquakescanada.nrcan.gc.ca/api/earthquakes/latest/7d.json

您还可以尝试使用$.getJSON(...)而不是$.ajax(...) ,因为那样会使您在data变量中解析出json对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM