1

下面的代码适用于除 IE 之外的所有浏览器(包括 Windows 7 上的 IE9)。请帮忙,我错过了什么或做错了什么?

示例:http: //jsfiddle.net/KBJwh/

- 更新 -

根据一些反馈,我更新了代码,var并添加了一个警报,其中包含对场地名称的超级简单调用。我仍然无法在 IE 上查看来自 JSON 的数据。

新示例:http: //jsfiddle.net/ZachSchneider/KBJwh/4/

先感谢您!

// 4sq API JSON
    var jsonURL = "https://api.foursquare.com/v2/venues/4a9fec80f964a520923d20e3?client_id=FPD2H4NAKX3ABYPEGR2LAMSWV41HC3GSWAEDOCVR00ZDS3LL&client_secret=FCV2G2P3MXZQE2HQYCLHPTMFR03ARE4MWLM34KOX4MXIKCX4&v=20130114";

    // Now let us go and grab that mayor from the API 
    jQuery.getJSON(jsonURL, function (data) {

        // Test Case
            jQuery.each(data.response, function(index, nm){
                    alert(nm.name);
            });

        // Looking through the JSON 
        jQuery.each(data.response.venue.mayor.user, function (i, item) {

            // Neededed 4sq variables 
            var photo = data.response.venue.mayor.user.photo.suffix,
            firstName = data.response.venue.mayor.user.firstName,
            lastName = data.response.venue.mayor.user.lastName,
            checkins = data.response.venue.mayor.count;

            // Content to append into HTML 
            currentMayor = '<img src="https://is1.4sqi.net/userpix_thumbs/' + photo + '"  width="55" height="55" /><p>Congrats, <span class="currentMayor">' + firstName + ' ' + lastName + ' ' + checkins + '</span> check-ins in the last 60 days</p>';
        });

        jQuery(currentMayor).prependTo("#myDIV");
    });
4

2 回答 2

1

我采用了.ajax()提供失败和成功属性的方法。

// 4sq API JSON
    var jsonURL = "https://api.foursquare.com/v2/venues/4a9fec80f964a520923d20e3?client_id=FPD2H4NAKX3ABYPEGR2LAMSWV41HC3GSWAEDOCVR00ZDS3LL&client_secret=FCV2G2P3MXZQE2HQYCLHPTMFR03ARE4MWLM34KOX4MXIKCX4&v=20130114";
var request = jQuery.ajax({
    url: jsonURL,
    context: document.body
});
// Yay! JSON is working 
request.success(function () {
    // Now let us go and grab that mayor from the API 
    jQuery.getJSON(jsonURL, function (data) {

        // Looking through the JSON 
        jQuery.each(data.response.venue.mayor.user, function (i, item) {

            // Neededed 4sq variables 
            var photo = data.response.venue.mayor.user.photo.suffix,
                firstName = data.response.venue.mayor.user.firstName,
                lastName = data.response.venue.mayor.user.lastName,
                checkins = data.response.venue.mayor.count;


            // Content to append into HTML 
            currentMayor = '<img src="https://is1.4sqi.net/userpix_thumbs/' + photo + '"  width="55" height="55" /><p>Congrats, <span class="currentMayor">' + firstName + ' ' + lastName + ' ' + checkins + '</span> check-ins in the last 60 days</p>';
        });
        jQuery(currentMayor).prependTo("#myDIV");
    });
});
// Foursquare failed or you are just using IE 
request.fail(function () {
    jQuery("<div>placeholder copy for IE or broken API</div>").prependTo("#myDIV");
});
于 2013-01-28T19:46:27.027 回答
0

尝试添加&callback=?到 URL 的末尾

于 2013-08-21T14:10:12.913 回答