View Full Version : Get local time using Ajax request from web service

29 Aug 2011, 2:52 AM
Hi there,
I'm trying to send a n Ajax request to this website: http://www.earthtools.org/webservices.htm using the following code:

Ext.regModel('Timezone', {
fields: ['localtime', 'isotime', 'utctime', 'location', 'offset', 'suffix', 'dst']

var store = new Ext.data.Store({
model: 'Timezone',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'http://www.earthtools.org/timezone/40.71417/-74.00639',
reader: {
type: 'xml',
model: 'Timezone',
record: 'timezone'

For some reason I cant get an answer although it generates an XML response:
Also, where or how can I catch the response?
I would like to present it to the user.
Many thanks

29 Aug 2011, 9:36 PM
Ok so after some tests I found out that Sencha's XML request dont accept the following:

<timezone xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone-1.1.xsd">
<localtime>30 Aug 2011 00:33:11</localtime>
<isotime>2011-08-30 00:33:11 -0500</isotime>
<utctime>2011-08-30 05:33:11</utctime>

To be more specific, it does not accept the first line of the XML respones!
Any chance anyone know how to bypass it?
Many thanks

30 Aug 2011, 12:33 AM
Write a custom xml reader, like this:

app.readers.customreader = Ext.extend(Ext.data.XmlReader, {

readRecords: function(doc) {
if (Ext.isArray(doc)) {
doc = doc[0];

* manipulate your xml here,
* e.g. strip the offending tags.
* Use Ext.DomQuery.selectNode

return app.readers.customreader.superclass.readRecords.call(this, doc);


Ext.data.ReaderMgr.registerType('customreader', app.readers.customreader);

But this is really just a work around, there might be other things you can tweak.

30 Aug 2011, 2:48 AM
Hi fx-mike,
Many thanks for your reply.
I decided to use a small "web service" so to manipulate the parameters before returning the data to Sencha.
I'm not sure it's a good Idea but I will go with it at least until I'll decide that its not working for me.
Just if you are interested below is how I've manipulated the data:

WebRequest request = WebRequest.Create("http://www.earthtools.org/sun/" + latitude + "/" + longitude + "/" + date + "/" + timezone + "/" + dst + "");

StreamReader stream = new StreamReader(request.GetResponse().GetResponseStream());
StringBuilder builder = new StringBuilder();
builder.Replace("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>", "<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
builder.Replace("<timezone xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.earthtools.org/timezone-1.1.xsd\">", "<timezone>");

Many thanks