PDA

View Full Version : ajax request, xml reader help



jaquin
27 Sep 2010, 9:16 PM
Hi,

I am currently a part of a development team that is developing applications using Sencha Touch.
Here are the Sencha Touch Classes we have tried to use but cannot create a working sample.


- Ajax request and JASONP request
- XML data reader



Our problem:
- When we use the ajax request, Access Control Allow origin is null. We know that the problem is access policy for cross domain so we tried using the JSONP but unfortunately the response is not a valid JSON format.
- The response from our service is in xml format so we tried to use php to get the response then write it on a xml file. Our next problem is how to read the xml file using the xml data reader of sencha.


We are always looking into your api documentation to help us in our RND but there is not much example included on it so we are here in sencha forum to get some help to make our code working. We don't have much knowledge on javascript so we are really trying hard to understand all the codes in secha. We will be really glad to hear from you.

jep
27 Sep 2010, 9:28 PM
Have you looked at the Data section of the Kitchen Sink demo yet?

http://dev.sencha.com/deploy/touch/examples/kitchensink/

jaquin
27 Sep 2010, 10:09 PM
Have you looked at the Data section of the Kitchen Sink demo yet?

http://dev.sencha.com/deploy/touch/examples/kitchensink/


yes. we also tried examples found in the examples and showcases section

kortovos
27 Sep 2010, 10:28 PM
I have had the exact same problem. I wanted to connect to web services who respond with xml. It took me quit a while, but I have managed it with a combination of PHP, PHP Soap and the stores. The PHP file serves as a proxy, circumventing the cross domain policy.

Defining the store

makeOrderListRequest = function() {
orderListStore = new Ext.data.Store({
model: 'orderList',
proxy: {
type:'ajax',
url: 'proxytest.php',
extraParams:{action: 'askorderlist',
value: '2010-08-01',
user: 'username',
password: 'password'
},
reader: {
type: 'xml',
record: 'order'
}
},
listeners: {
single: true,
read: function(store, records, success){ --> store has no Callback
console.log('Store has done reading, new number of records is ' + store.getCount());
}
},
});
orderListStore.proxy.actionMethods.read= 'POST'; --> necessary, otherwise the method will be a 'GET'
orderListStore.read();
};Proxytest.php


define ('HOSTNAME', 'http://urltowebservice?wsdl');
// Get the parameters from the POST and construct the xml body with it.
if ($_POST['action']) {
$postvars = '';
while ($element = current($_POST)) {
if(key($_POST) != 'action'){
$postvars .= '<'.urlencode(key($_POST)).'>'.urlencode($element).'</'.urlencode(key($_POST)).'>';
}
next($_POST);
}
$postvars = '<'.$_POST['action'].'>'.$postvars.'</'.$_POST['action'].'>';

$client = new SoapClient(HOSTNAME);
header("Content-Type: text/xml"); --> necessary, otherwise response is text/html
echo($client->$_POST['action']($postvars));
}else{
echo 'Error : Parameters are not properly specified';
}Model orderList

Ext.regModel('orderList', {
fields : [ {
name : 'orderid',
type: 'integer'
}]
});Response from webservice

<?xml version="1.0" encoding="UTF-8"?>
<orderlist>
<order>
<orderid>
2005048
</orderid>
</order>
<order>
<orderid>
3000359
</orderid>
</order>
<order>
<orderid>
2007062
</orderid>
</order>
<order>
<orderid>
2007118
</orderid>
</order>
<order>
<orderid>
3000362
</orderid>
</order>
</orderlist>


Does this help you?

jaquin
28 Sep 2010, 1:05 AM
@kortovos

thank you for posting an example. we are currently trying it out.