我一直在尝试让一个简单的 Ext.js 应用程序工作,它从数据库中获取数据并将其显示在 ext.js 网格中,但我总是得到的唯一东西是“Failure:true”。也许您可以向我指出错误。
这是 index.php:
<html>
<head>
<script src="extjs/ext-dev.js" type="text/javascript"></script>
<script src="mainscript.js" type="text/javascript"></script>
</head>
<body>
<?php
$conn = mysql_connect('localhost','admin','1234','cdcol') or die ('Error connecting to mysql');
$task = '';
if ( isset($_POST['task'])){
$task = $_POST['task'];
}
switch($task){
case "LISTING":
getList();
break;
default:
echo "{failure:true}";
break;
}
function getList(){
$query = mysql_query("SELECT * FROM cdcol.cds");
$cds = array();
while($row = mysql_fetch_array($query)){
$cds[] = array('titel' => $row['titel'], 'jahr' => $row['jahr'],'interpret' => $row['interpret'], 'id' => $row['id']);
}
$jsonresult = json_encode(array('cds'=>$cds));
}
?>
</body>
这将是 mainscript.js:
var cdDataStore;
var cdColumnModel;
var cdEditorGrid;
var cdWindow;
Ext.onReady(function(){
Ext.QuickTips.init();
cdDataStore = new Ext.data.Store({
id: 'cdDataStore',
proxy: new Ext.data.HttpProxy({
url: 'index.php',
method: 'POST'
}),
baseParams:{task: "LISTING"},
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'id'
},[
{name: 'titel', type: 'string', mapping: 'titel'},
{name: 'interpret', type: 'string', mapping: 'interpret'},
{name: 'jahr', type: 'int', mapping: 'jahr'},
{name: 'id', type: 'int', mapping: 'id'}
]),
sortInfo:{field: 'jahr', direction: "ASC"}
});
cdColumnModel = new Ext.grid.ColumnModel(
[{
header: '#',
readOnly: true,
dataIndex: 'id',
width: 50,
hidden: false
},{
header: 'titel',
dataIndex: 'titel',
width: 150,
},{
header: 'interpret',
dataIndex: 'interpret',
width: 150,
},{
header: 'jahr',
readOnly: true,
dataIndex: 'jahr',
width: 50,
},{
header: 'id',
dataIndex: 'id',
width: 150,
readOnly: true
}]
);
cdColumnModel.defaultSortable= true;
cdEditorGrid = new Ext.grid.EditorGridPanel({
id: 'cdListingEditorGrid',
store:cdDataStore,
cm: cdColumnModel,
enableColLock:false,
clicksToEdit:1,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false})
});
cdListingWindow = new Ext.Window({
id: 'cdListingWindow',
title: 'some cds',
closable:true,
width:700,
height:350,
plain:true,
layout: 'fit',
items: cdListingEditorGrid
});
cdDataStore.load();
cdListingWindow.show();
});
任何帮助或不同的方法将不胜感激!