2012-05-12 106 views
2

我有一個問題,螢火蟲不告訴我任何問題:/煎茶網+ PHP + JSON

我funcions.js

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 

Ext.require([ 
    'Ext.grid.*', 
    'Ext.data.*', 
    'Ext.util.*', 
    'Ext.state.*' 
    ]); 

Ext.onReady(function() { 
    Ext.QuickTips.init(); 

    // setup the state provider, all state information will be saved to a cookie 
    Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider')); 

    var store = Ext.create('Ext.data.Store', { 
     autoLoad: true, 
     proxy: { 
      type: 'ajax', 
      url: 'src.php' 
     } 
    }); 
    var grid = Ext.create('Ext.grid.Panel', { 
     store: store, 
     stateful: true, 
     collapsible: true, 
     multiSelect: true, 
     stateId: 'stateGrid', 
     columns: [ 
     { 
      text  : 'Nombre Chofer', 
      flex  : 1, 
      sortable : false, 
      dataIndex: 'nombre_chofer' 
     } 
     ], 
     height: 350, 
     width: 600, 
     title: 'Array Grid', 
     renderTo: 'grid-example', 
     viewConfig: { 
      stripeRows: true, 
      enableTextSelection: true 
     } 
    }); 
}); 

我src.php(AJAX)

<?php 

include_once 'funciones/header_server.php'; 
include_once 'model/ChoferModel.php'; 

function getList() { 
    $choferModel = new ChoferModel(); 
    $resultQuery = $choferModel->getTable(); 
    $conteo = count($resultQuery) - 1; 
    $resultQuery = (array) $resultQuery; 

    if ($conteo > 0) { 
     foreach ($resultQuery as $chofer) { 
      $rec['nombre_chofer'] = $chofer['NOMBRE_CHOFER']; 
      $arr[] = $rec; 
     } 
     $jsonresult = JEncode($arr); 
     echo $jsonresult; 
    } 
} 

getList(); 

和我的index.php

<?php 
//include_once 'funciones/header_server.php'; 
//include_once 'model/ChoferModel.php'; 
?> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>Sistema para control de viaticos - COPRA</title> 
     <link rel="stylesheet" type="text/css" href="script/ext-all.css" /> 
     <script type="text/javascript" charset="utf-8" src="script/ext-all-dev.js"></script> 
     <script type="text/javascript" charset="utf-8" src="script/ext.js"></script> 
     <script src="script/funcions.js"></script> 
    </head> 
    <body> 
     <div id="grid-example" name="grid-example"></div> 
    </body> 
</html> 

我的輸出是雙語K,不顯示錶或網格化......請幫助我..

截圖: SRC輸出:http://i.stack.imgur.com/zLMgz.png

回答

1

只要定義自己的模型,並在阿賈克斯代理設置使用它。

請參閱working example您的代碼。

0

將代理配置放入模型中存入。這在我的應用程序中適用於我。

這裏如何配置我的模型:

proxy: {

type: 'ajax', 
api: { 
    read: 'scripts/receive.php', 
    create: 'scripts/create.php?action=create', 
    update: 'scripts/create.php?action=update', 
    destroy:'scripts/destroy.php?action=destroy' 
}, 

reader: { 
    type: 'json', 
    root: 'groups' 
}, 

0

也許,你必須設置你的PHP作爲JSON的響應。添加到您的php

header("HTTP/1.1 200 OK"); 
header("Content-Type: application/json");