开发者

Problem with jTemplate reading from JSON web service, resulting in fcount not defined error

I have the following jTemplate (jtemplate.python.org):

<li>
    <p>Found {$T.TotalRecords} airports</p>
</li>
{#foreach $T.AirportList as Airport}
<li class="airport-row">
    <div class="gowalla-avatar">
        <a href="/airport/{toLower($T.Airport.Icao)}">
            <img src="{$T.Airport.GowallaImgSmall}" alt="{$T.Airport.AirportName}" title="{$T.Airport.AirportName}" width="100" height="100" border="0"></img>
        </a>
    </div>
    <div class="gowalla-spot">
        <a class="gowalla-name" href="/airport/{toLower($T.Airport.Icao)}">{$T.Airport.AirportName}&nbsp;({$T.Airport.Iata})</a>
        <small>
            <img src="/images/iconography/marker-tiny.png" alt="" class="padtop tinyicon"></img><a href="/city/{toLower(safeUrl($T.Airport.City))}/{toLower(safeUrl($T.Airport.Country))}/">{$T.Airport.City}</a>, <a href="/country/{toLower(safeUrl($T.Airport.Country))}">{$T.Airport.Country}</a><br />
            <a href="#" id="flyfromhere">Fly from here &raquo;</a>&nbsp;|&nbsp;<a href="#" id="flytohere">Fly to here &raquo;</a>
        </small>

    </div>
</li>
{#/for}

And I have the following jQuery which calls the template:

$.ajax({
            type: "POST",
            url: "/AtomicService/Cog.asmx/GetAirports",
            data: defaultParameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: (function Success(data, status) {
                $('#placeholder').setTemplateURL('/templates/html/airports.htm?ck=' + cachekiller, null, { filter_data: false });
                $('#placeholder').processTemplate(data.d);
            }),
            error: (function Error(request, status, error) {
                $("#placeholder").html(request.statusText).fadeIn(1000);
                loader(false);
            })
        });

EDIT 1 (now showing the full JSON rather than a cut-down version) The Cog.asmx web service returns this:

{"d":[{"__type":"AtomicCore.Model.AirportsMeta","PageNumber":0,"TotalRecords":18,"PageSize":25,"Filter":"","AirportList":[{"Icao":"sbbr","Iata":"BSB","GowallaId":"88087","GowallaImgSmall":"http://static.gowalla.com/categories/45-6de6285cf723cb1b638a55592996e0db-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/45-d87d711baffea5449a5be5d76cc269a9-200.png","City":"Brasília","Country":"Brazil","CityId":18,"CountryId":13,"AirportName":"Brasília International Airport","Lat":"15_52_16_S","Lon":"047_55_07_W","Notes":"","TwitterUsername":""},{"Icao":"tqpf","Iata":"AXA","GowallaId":null,"GowallaImgSmall":"http://static.gowalla.com/categories/45-6de6285cf723cb1b638a55592996e0db-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/45-d87d711baffea5449a5be5d76cc269a9-200.png","City":"The Valley","Country":"Anguilla","CityId":17,"CountryId":11,"AirportName":"Clayton J. Lloyd International Airport","Lat":"18_12_17_N","Lon":"063_03_18_W","Notes":null,"TwitterUsername":""},{"Icao":"daag","Iata":"ALG","GowallaId":"6342428","GowallaImgSmall":"http://static.gowalla.com/categories/224-45108e7cf9bda7f2b7fcf2d9936062df-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/224-ab0ffef2a59be2962f25fa05a6c01ee8-200.png","City":"Algiers","Country":"Algeria","CityId":13,"CountryId":5,"AirportName":"Houari Boumediene Airport","Lat":"36_41_27.65_N","Lon":"003_12_55.47_E","Notes":null,"TwitterUsername":""},{"Icao":"kjfk","Iata":"JFK","GowallaId":"23261","GowallaImgSmall":"http://static.gowalla.com/spots/23261-a2fe6d3cdaf09baa58ab88dbf625055a-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/23261-adaaaef09af986fde61eeebe1f352cca-200.png","City":"New York","Country":"United States of America","CityId":2,"CountryId":1,"AirportName":"John F. Kennedy International","Lat":"40_38_23_N","Lon":"-73_46_44_W","Notes":null,"TwitterUsername":""},{"Icao":"klga","Iata":"LGA","GowallaId":"12505","GowallaImgSmall":"http://static.gowalla.com/spots/12505-0df5060f5bd0931f7029abb98a2bcb13-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/12505-e9083d20dd2bf6f9f3928ac69684eef5-200.png","City":"New York","Country":"United States of America","CityId":2,"CountryId":1,"AirportName":"LaGuardia Airport","Lat":"40_46_38.1_N","Lon":"-73_52_21.4_W","Notes":null,"TwitterUsername":""},{"Icao":"kbos","Iata":"BOS","GowallaId":"14128","GowallaImgSmall":"http://static.gowalla.com/spots/14128-6b5e1275b7b9fa43e85d1453bcb10bf5-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/14128-b53c8a09a6fec9a1c2cf476e078306cd-200.png","C开发者_如何学Goity":"Boston","Country":"United States of America","CityId":3,"CountryId":1,"AirportName":"Logan International","Lat":"42_21_47_N","Lon":"-071_00_23_W","Notes":null,"TwitterUsername":"bostonlogan"},{"Icao":"egkk","Iata":"LGW","GowallaId":"25673","GowallaImgSmall":"http://static.gowalla.com/spots/25673-13a2e648f8abaddade95a1616793dec1-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/25673-9e507d6d6edbed9ca0b6ccc402e0d197-200.png","City":"London","Country":"United Kingdom","CityId":16,"CountryId":2,"AirportName":"London Gatwick","Lat":"51_08_53_N","Lon":"-000_11_25_W","Notes":null,"TwitterUsername":"Gatwick_Airport"},{"Icao":"egll","Iata":"LHR","GowallaId":"22833","GowallaImgSmall":"http://static.gowalla.com/spots/22833-149de856d0f461238a0fb3e8254472af-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/22833-4536a8f8b3bc0844ce7798ffd51be092-200.png","City":"London","Country":"United Kingdom","CityId":16,"CountryId":2,"AirportName":"London Heathrow International","Lat":"51_28_39_N","Lon":"-000_27_41_W","Notes":null,"TwitterUsername":"HeathrowAirport"},{"Icao":"kmsy","Iata":"MSY","GowallaId":"26646","GowallaImgSmall":"http://static.gowalla.com/spots/26646-43f31d3de18485cd848adc93e19abc58-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/26646-ea7ba53c06d9d9a58fe0cc7bd9528bc3-200.png","City":"New Orleans","Country":"United States of America","CityId":4,"CountryId":1,"AirportName":"Louis Armstrong International Airport","Lat":"29_59_36_N","Lon":"-090_15_29_W","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"kmia","Iata":"MIA","GowallaId":"631060","GowallaImgSmall":"http://static.gowalla.com/spots/631060-ad544a584a7a5abc2d85d3bab9cb01fe-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/631060-16ede5f297e58d00455bbc96164af157-200.png","City":"Miami","Country":"United States of America","CityId":5,"CountryId":1,"AirportName":"Miami International Airport","Lat":"25_47_36_N","Lon":"-080_17_26_W","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"nstu","Iata":"PPG","GowallaId":null,"GowallaImgSmall":"http://static.gowalla.com/spots/631060-ad544a584a7a5abc2d85d3bab9cb01fe-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/631060-16ede5f297e58d00455bbc96164af157-200.png","City":"Pago Pago","Country":"American Samoa","CityId":9,"CountryId":7,"AirportName":"Pago Pago International Airport","Lat":"14_19_54_S","Lon":"170_42_41_W","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"lfpg","Iata":"CDG","GowallaId":"23249","GowallaImgSmall":"http://static.gowalla.com/spots/23249-4bfb498826b1d283bf3cbccef252e51d-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/23249-7dcd25adfb0e84f83523802f2b6b7f1b-200.png","City":"Paris","Country":"France","CityId":14,"CountryId":9,"AirportName":"Paris-Charles de Gaulle Airport","Lat":"49_00_35_N","Lon":"002_32_52_E","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"lfmp","Iata":"PGF","GowallaId":"449813","GowallaImgSmall":"http://static.gowalla.com/categories/45-6de6285cf723cb1b638a55592996e0db-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/45-d87d711baffea5449a5be5d76cc269a9-200.png","City":"Perpignan","Country":"France","CityId":12,"CountryId":9,"AirportName":"Perpignan - Rivesaltes Airport","Lat":"42_44_26_N","Lon":"002_52_14_E","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"fnlu","Iata":"LAD","GowallaId":null,"GowallaImgSmall":"http://static.gowalla.com/categories/45-6de6285cf723cb1b638a55592996e0db-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/45-d87d711baffea5449a5be5d76cc269a9-200.png","City":"Luanda","Country":"Angola","CityId":15,"CountryId":10,"AirportName":"Quatro de Fevereiro Airport","Lat":"08_51_30_S","Lon":"013_13_52_E","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"kdca","Iata":"DCA","GowallaId":"15684","GowallaImgSmall":"http://static.gowalla.com/spots/15684-8f64518d2d4035c6b023d01f6c109cb5-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/15684-78b9b15f47b02049e0e26e7851b673dd-200.png","City":"Washington D.C.","Country":"United States of America","CityId":1,"CountryId":1,"AirportName":"Ronald Reagan Washington National Airport","Lat":null,"Lon":null,"Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"lati","Iata":"TIA","GowallaId":"1165055","GowallaImgSmall":"http://static.gowalla.com/categories/45-6de6285cf723cb1b638a55592996e0db-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/45-d87d711baffea5449a5be5d76cc269a9-200.png","City":"Tirana","Country":"Albania","CityId":8,"CountryId":4,"AirportName":"Tirana International Airport Nënë Tereza","Lat":"41_24_53_N","Lon":"19_43_14_E","Notes":null,"TwitterUsername":"NO_Airport"},{"Icao":"tapa","Iata":"ANU","GowallaId":"","GowallaImgSmall":"http://static.gowalla.com/categories/45-6de6285cf723cb1b638a55592996e0db-100.png","GowallaImgLarge":"http://static.gowalla.com/categories/45-d87d711baffea5449a5be5d76cc269a9-200.png","City":"St John\u0027s","Country":"Antigua and Barbuda","CityId":19,"CountryId":14,"AirportName":"V. C. Bird International Airport","Lat":"17_136667","Lon":"-61_792778","Notes":"","TwitterUsername":"NO_Airport"},{"Icao":"kiad","Iata":"IAD","GowallaId":"12802","GowallaImgSmall":"http://static.gowalla.com/spots/12802-0fd0d39f94797d59e2db5c8fc20a8990-100.png","GowallaImgLarge":"http://static.gowalla.com/spots/12802-1701e67a1847c40abeadc5afabedcc9e-200.png","City":"Washington D.C.","Country":"United States of America","CityId":1,"CountryId":1,"AirportName":"Washington Dulles International","Lat":"38_56_40_N","Lon":"-077_27_21_W","Notes":null,"TwitterUsername":"NO_Airport"}]}]}

Despite that, I get an fcount not defined error within the jtemplate.js file and I can't seem to read out the values within the d object after the success method is called. Have I been staring at this too long to see what I'm doing wrong?


i have tested this locally and it works

$(function(){

    $.getJSON("anotherJSON.json", function(json) {   
        alert(json.d[0].AirportList[0].AirportName);  //alerts Brasília International Airport

   });
});

one with ajax like you did in your question

$(function(){
   $.ajax({
            type: "POST",
            url: "anotherJSON.json",                        
            dataType: "json",
            success:function(data, status) {
            alert("success");
             alert(data.d[0].AirportList[0].AirportName); 

            },
            error:function(request, status, error) {
               alert("o0ops");
            }
        });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜