json数据没有以html格式显示

时间:2017-02-04 12:48:52

标签: javascript jquery json ajax

我试图从网址显示数据,它是以json的形式。我的ajax代码如下

function loadMore(url) {
            alert(url);
             $.ajax({
              dataType: "json",
              url: url,
              data: data,
              success: function (data) {
                    alert(data);
                    var table = document.getElementById("claimList");
                    for (var i=0; i < data.length; i++) {

                        var row = table.insertRow(-1);
                        var cell1 = row.insertCell(0);
                        var cell2 = row.insertCell(1);
                        var cell3 = row.insertCell(2);
                        cell3.style.width = '25px';

                        // Add some text to the new cells:
                        cell1.innerHTML = '<td><a href="../institutedetails?businessId={{ data.businessId }}">{{ data.displayName }}</a></td>';
                        cell2.innerHTML = '<td>{{ data.businessAddress }}</td>';
                        cell3.innerHTML = '<td>{{ data.businessLocation }}</td>';
                    }


               },
              error: function (request, error) {
                    console.log(arguments);
                    alert(" Can't load more because " + error);
                },
            });
        }

和html代码如下

<div class="row row-centered">
        <div class="col-md-10 col-md-offset-1">
            <div class="col-md-12">
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-striped tablesorter" id="claimList">
                        <thead>
                            <tr>
                                <th class="header"> Institute Name <i class="icon-sort"></i></th>
                                <th class="header"> Address <i class="icon-sort"></i></th>
                                <th class="header"> Location <i class="icon-sort"></i></th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for key in data %}
                            <tr>
                                <td><a href="../institutedetails?businessId={{ key.businessId }}">{{ key.displayName }}</a></td>
                                <td>{{ key.businessAddress }}</td>
                                <td>{{ key.businessLocation }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    <ul class="pager">
                        <li class="next"><button class="btn btn-default" name="load_more" id="load_more" onclick="loadMore('{{ nextPage }}');">Load More</button></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

数据是json的形式,它来自网址,但我不知道如何通过ajax显示数据

0 个答案:

没有答案