2013-05-05 76 views
0

的所有JSON數據。jqGrid未填充來自PHP

我一直試圖讓這個工作整天。我認爲我的JSON數據正在以正確的格式返回,但網格空了。

你可以看到兩個網格,這是我打印成字符串按照這個網址的數據:

http://wptest.andrux.net/?p=371

這裏是我的PHP代碼:

/* connect to the database */ 
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) 
     or die('Connection Error: ' . mysql_error()); 

    mysql_select_db(DB_NAME) 
     or die('Error connecting to database ' . DB_NAME); 

    $options = get_option('my-queries'); 

    /* most queries are saved with escaping quotes */ 
    $query = stripslashes($options[ $_POST['id'] ]['query']); 

    $result = mysql_query($query) 
     or die('Couldn\'t execute query. ' . mysql_error()); 

    /* load column names from the database */ 
    $col_names = array(); 
    while ($column = mysql_fetch_field($result)) { 
     $col_names[] = $column->name; 
    } 

    $response->page = 1; 
    $response->total = 1; 
    $response->records = mysql_num_rows($result); 
    $i = 0; 

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
     $cells = array(); 
     foreach ($col_names as $col_name) { 
      $cells[] = $row[ $col_name ]; 
     } 
     $response->rows[ $i ]['id'] = $cells[0]; 
     $response->rows[ $i ]['cell'] = $cells; 
     $i++; 
    } 

    echo json_encode($response); 

,這裏是我的javascript:

var data = { 
     action: 'build_jqgrid_table', 
     id: 0 
    }; 

$.post('http://wptest.andrux.net/wp-admin/admin-ajax.php', data, function(response) { 
    $('#test-div').html(response); 
}); 


$('#db-query-shortcode-table').jqGrid({ 
    url: 'http://wptest.andrux.net/wp-admin/admin-ajax.php?action=build_jqgrid_table&id=0', 
    datatype: 'json', 
    colNames: [ 
     'Submitted', 
     'changed_address', 
     'cancelled_subscription', 
     'name', 
     'address1', 
     'address2', 
     'city', 
     'state', 
     'zip', 
     'country', 
     'phone', 
     'email', 
     'Submitted_Login', 
     'Submitted_From', 
     'fields_with_file' 
    ], 
    colModel: [ 
     { name: 'Submitted', index: 'Submitted', width: 55, editable: true }, 
     { name: 'changed_address', index: 'changed_address', width: 55, editable: true }, 
     { name: 'cancelled_subscription', index: 'cancelled_subscription', width: 55, editable: true }, 
     { name: 'name', index: 'name', width: 55, editable: true }, 
     { name: 'address1', index: 'address1', width: 55, editable: true }, 
     { name: 'address2', index: 'address2', width: 55, editable: true }, 
     { name: 'city', index: 'city', width: 55, editable: true }, 
     { name: 'state', index: 'state', width: 55, editable: true }, 
     { name: 'zip', index: 'zip', width: 55, editable: true }, 
     { name: 'country', index: 'country', width: 55, editable: true }, 
     { name: 'phone', index: 'phone', width: 55, editable: true }, 
     { name: 'email', index: 'email', width: 55, editable: true }, 
     { name: 'Submitted_Login', index: 'Submitted_Login', width: 55, editable: true }, 
     { name: 'Submitted_From', index: 'Submitted_From', width: 55, editable: true }, 
     { name: 'fields_with_file', index: 'fields_with_file', width: 55, editable: true } 
    ], 
    rowNum: 10, 
    rowList: [ 10, 20, 30 ], 
    pager: '#db-query-pager', 
    sortname: 'Submitted', 
    viewrecords: true, 
    sortorder: 'desc', 
    //editurl: 'server.php', 
    caption: 'Test table' 
}); 

$('#db-query-shortcode-table').jqGrid('navGrid', '#db-query-pager', { edit: false, add: false, del: false }); 
$('#db-query-shortcode-table').jqGrid('inlineNav', '#db-query-pager'); 

任何人誰知道我缺少什麼?

謝謝大家提前

回答

0

好了,因爲沒有人能夠幫助kqGrid,我剛搬到另一個庫。 jqGrid可能爲其他人完美地工作,但這是我3年來第二次使用它,至少在我的情況下,使它工作是一種痛苦 - 第一次使用tableToGrid(),但這一次甚至不是這樣幫助。

無論如何,對於那些感興趣的,jQuery EasyUI工程很好,它很容易設置。

問候大家。

+0

我沒有時間測試,但我認爲我使用jqGrid的問題可以通過將jqGrid表格封裝在iframe中來解決 – andrux 2013-05-07 17:51:08