Bootstrap表不能通过URL工作

时间:2018-04-02 21:12:59

标签: jquery ajax twitter-bootstrap

我正在尝试从PHP加载JSON数据:

$array= ["COL1"=> "data1","COL2"=> "data2"];
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
echo json_encode($array);

到下表:

 <table  data-ajax="ajaxRequest" id="table" data-side-pagination="server" data-toggle="table"  data-search="true" data-pagination="true" data-show-columns="true" data-detail-view="true" data-detail-formatter="ppg">
                <thead>
                <tr>
                    <th data-field="COL1" data-sortable="true">COL1</th>
                    <th data-field="COL2" data-sortable="true">COL2</th>
                </tr>
                </thead>

            </table>
function ajaxRequest(params) {
    console.log(params.data);

    $.ajax({
        type: "POST",
        url: "http://www.my-url.com/script.php",
        data: "",
        dataType: "json",
        success: function (data) {
            params.success({
                "rows": data,
                "total": data.length
            })
        },
        error: function (er) {
            params.error(er);
        }
    });
}

正确下载数据并将数据写入本地文件可以正常工作,但它不会将数据读入表中。我不确定我在哪里弄错了?

0 个答案:

没有答案