jerkovicl
2/28/2014 - 8:29 AM

JSON to HTML example

JSON to HTML example

<script type="text/javascript">
    $(document).ready(function () {

        var sf = $.ServicesFramework(-1);
        // Send an AJAX request
        $.getJSON(sf.getServiceRoot('eTailer.NewProducts') + "NewProductsAPI/GetNewProducts?CategoryId=2&Top=10",
            function (data) {
                // On success, 'data' contains a list 
                $.each(data, function (key, val) {
                    // Format the text to display.
                    var str = val.productName + val.productDescription + val.productPrice + "</br>" + "<img src='http://bicikla/DesktopModules/eTailer/ImageHandler.ashx?ProductID=" + val.productId +"'/>"
                    // Add a list item for the product.
                    $('<li/>', { html: str }).appendTo($('#content'));
                });
            });
    });

    </script>