簡體   English   中英

帶有JSON字符串的jQuery DataTable

[英]jquery DataTable with JSON string

嗨:直截了當。
我試圖從ajax調用傳遞JSON字符串作為數據源PHP代碼

if($_POST){
    $action = $_POST["action"];
    if($action == "call_data"){
        header('Content-type: application/json');  
        include_once 'clases/Usuario.class.php';  
        $usuario = new Usuario;  
        $resultado = $usuario->listar_jefes ();  
        if ( ! $resultado )  
        {  
            exit ("nok");  
        }  
        exit (json_encode ($resultado));  
    }
}

還有我的jQuery代碼。

$.post("function.php", {action:"call_data"},function(jsonstr){  
    $("#usr_table").dataTable({  
        "bProcessing": true,  
        "sAjaxSource": jsonstr  
    });
});

但這不起作用...任何幫助將不勝感激

編輯:我把我的桌子...以防萬一:

<table id="usr_table">
    <thead>
        <tr>
            <th>col1</th>
            <th>col2</th>
            <th>col3</th>
        </tr>
    </thead>
    <tbody>
        <tr>

        </tr>
    </tbody>
    <tfoot>
        <tr>
            <th>col1</th>
            <th>col2</th>
            <th>col3</th>
        </tr>
    </tfoot>
</table>

您是否能恢復數據? 如果是這樣,您可能需要將數據轉換回json對象。

var json_object = eval('(' + returned_data_string + ')');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM