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 に答える