我的 PHP 代码从数据库中正确读取,我可以运行 PHP 代码并查看 XML。在闪存中,我没有错误,数据网格正确显示,但数据根本不存在。
PHP 代码
mysql_connect('localhost', 'root', '');
mysql_select_db('menu');
$sql = "SELECT item_name, item_price FROM menu1";
$res = mysql_query($sql);
header('Content-Type: application/xml');
print "<root>";
while ($row = mysql_fetch_assoc($res)) {
print "<items><itemname>".$row['item_name']."</itemname><itemprice>".$row['item_price']." </itemprice></items>";
}
print "</root>";
AS3 代码
import fl.controls.DataGrid;
import fl.data.DataProvider;
var data_grid:DataGrid = new DataGrid();
data_grid.addColumn("itemname");
data_grid.addColumn("itemprice");
data_grid.width = 600;
data_grid.rowCount = 2;
data_grid.move(10, 70);
addChild(data_grid);
var dp:DataProvider;
var request:URLRequest = new URLRequest("localhost/menu3.php");
var url_loader:URLLoader = new URLLoader();
url_loader.addEventListener(Event.COMPLETE, completeHandler);
url_loader.load(request);
function completeHandler(event:Event):void {
var ldr:URLLoader = event.currentTarget as URLLoader;
var xmlDP:XML = new XML(ldr.data);
dp = new DataProvider(xmlDP);
data_grid.dataProvider = dp;
}