Click here to Skip to main content
15,900,649 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
    <script>
        $(function () {
            //var dmJSON = "http://api.dailymile.com/entries.json?callback=?";
            var dmJSON = "http://localhost:61397/CompanyRestService.svc/GetCompID/155?callback=?";
            $.getJSON(dmJSON, function (data) {
                alert("The values can't come this method..?");
                $.each(data.SelectCompanyDetailsResult, function (i, f) {
                    var tblRow = "<tr>" + "<td>" + f.AliasName + "</td>" + "<td>" + f.CIN + "</td>" + "</tr>"
                    $(tblRow).appendTo("#entrydata tbody");
                });
            }
            );
        });
    </script>
</head>
<body>
    <div class="wrapper">
        <div class="profile">
            <table id="entrydata" border="1">
                <thead>
                <th>AliasName</th>
                <th>CIN</th>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</body>
</html>



exaple my Json output:

{"SelectCompanyDetailsResult":[{"AliasName":"HCL","CIN":"U72900Te2003P1699","Websites":"www.okdude.co"}]}

What I have tried:

I struggled for a long time To load Json data to html table...plz help
Posted
Updated 21-Jun-16 3:03am
Comments

1 solution

Hi,

I have check with your code there has not been any problem to load json data to html table.

it might problem with your data. i have check code in local with your given static data it's work perfectly.

Check below code to load static data into html table

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
    <script>
        $(document).ready(function () {
            //var dmJSON = "http://api.dailymile.com/entries.json?callback=?";
            var testdata = [{ "AliasName": "HCL", "CIN": "U72900Te2003P1699", "Websites": "www.okdude.co" }];
           // $.getJSON(dmJSON, function (data) {
                alert("The values can't come this method..?");
                $.each(testdata, function (i, f) {
                    var tblRow = "<table><tbody><tr>" + "<td>" + f.AliasName + "</td>" + "<td>" + f.CIN + "</td>" + "</tr></tbody></table>"
                    $(tblRow).appendTo("#entrydata tbody");
                });
            //}
            //);
        });
    </script>
</head>
<body>
    <div class="wrapper">
        <div class="profile">
            <table id="entrydata" border="1">
                <thead>
                <th>AliasName</th>
                <th>CIN</th>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900