PDA

View Full Version : Loading XML data into data.Store into a ComboBox



yousefomar
13 Jul 2009, 4:09 PM
Hi
I appreciate any help on why I'm not getting the data into the ComboBox?

when I use a static xml file it works fine, but when I use a php file that returns xml it doesn't even though I'm using header('Content-type: text/xml'); ... any suggestion please ?

PHP file: agent.php



<?php
header('Content-type: text/xml');
echo "
<?xml version="1.0" encoding="UTF-8"?>
<agents>
<Agent>
<agentid>10560</agentid>
<agentinfo>192.168.1.160 - 10560</agentinfo>
</Agent>
<Agent>
<agentid>10565</agentid>
<agentinfo>192.168.1.165 - 10565</agentinfo>
</Agent>
</agents>";
?>
Javascript file: agents.js



Ext.onReady(function(){

var agentsStore = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'agent.php'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Agent" tag
record: 'Agent'
}, [
'agentid', 'agentinfo'
])
});

agentsStore.load();


var win = new Ext.Window({
baseCls: '',
layout: 'form',
bodyStyle:'padding:10px 5px 10px 10px',
labelWidth: 110,
defaults: {width: 230},
defaultType: 'textfield',
items: [{
fieldLabel: 'IP address / Name',
name: 'host',
allowBlank: false
}, new Ext.form.ComboBox({
fieldLabel: 'Select Agent',
lazyRender:true,
name: 'int_agent',
mode: 'local',
loadingText:"Loading Agents",
store: agentsStore,
valueField: 'agentid',
displayField: 'agentinfo'
})]
});
win.show();
});

yousefomar
14 Jul 2009, 10:10 AM
this is fixed by changing this line of php


echo "
<?xml version='1.0' encoding='UTF-8'?>
to remove the newline before <?xml :


echo "<?xml version='1.0' encoding='UTF-8'?>

steffenk
14 Jul 2009, 11:34 AM
2 time wrong colons:

echo '<?xml version="1.0" encoding="UTF-8"?> ... ';