我如何使用jQuery.getJSON()获取此URL的数据?
http://gbrds.gbif.org/registry/organisation/a3c228d0-3110-11db-abb8-b8a03c50a862.json?op=contacts
如果我在浏览器中查看结果,我会得到以下结果:
[{"position":"","lastName":"","phone":"+39 06 6118286","type":"technical","city":"","country":"","isPrimaryContact":true,"postalCode":"","address":"","email":"m.skofic@cgiar.org","description":"","province":"","firstName":"Milko Skofic","salutation":"","key":"48"},{"position":"","lastName":"","phone":"39-06-6118204","type":"administrative","city":"","country":"","isPrimaryContact":true,"postalCode":"","address":"IPGRI, Via Tre Denari, 472/a, 00057, Maccarese, Rome, Italy,","email":"eurisco@cgiar.org","description":"","province":"","firstName":"Ms. Sonia Dias","salutation":"","key":"49"}]
答案 0 :(得分:1)
查看jQuery文档中的getJSON
方法。
Sintaxe:
$.getJSON(url, data, function success);
所以,你可以尝试这样的事情:
$.getJSON("http://gbrds.gbif.org/registry/organisation/a3c228d0-3110-11db-abb8-b8a03c50a862.json?op=contacts", null, function(data) {
// loop in your result if it is an array
$.each(data, function(i, item) {
// use data[i].property to access each property of your array.
// for sample:
var p = data[i].position;
var l = data[i].lastName;
});
});
答案 1 :(得分:0)
如果您要求来自其他架构/主机/端口组合的网址(例如https://gbrds.gbif.com:8080
),则由于违反了same-origin policy
如果你能实现jquery也支持的jsonp,那么就可以解决这个问题。
答案 2 :(得分:0)
您需要使用JSONP,因为它不在同一个域中。
$.getJSON("http://gbrds.gbif.org/registry/organisation/a3c228d0-3110-11db-abb8-b8a03c50a862.json?op=contacts&callback=?", function(data) {
console.log(data);
});