0

I need to read content from a data source which is located on a remote server (I do not have access to modify anything).

I have tried to get the content, but it doesn't work.

What then I did was I downloaded this data source which is a XML file and put it under same folder with my code to test the correctness of my code syntax and found that the code works.

But when I changed back to the external data resource, it still reads but returns no content:

from: url: 'app/store/configuration.xml'
to:   url: 'http://webtrak.bksv.com/mel/configuration'

This is not caused by CORS issue as I am testing my app on real devices.

Here are my store and model:

Ext.define('myApp.store.SensorStationStore', {
    extend: 'Ext.data.Store',
    requires: ['myApp.model.SensorStation', 'Ext.data.reader.Xml'],
    config:{
        model: 'myApp.model.SensorStation',
        storeId: 'SensorStore',
        autoLoad: true,
        proxy: {
                 type: 'ajax',
                 url: 'http://webtrak.bksv.com/mel/configuration',
                 //url: 'app/store/configuration.xml',
                 reader: {
                     type: 'xml',
                     record: 'locations',
                     rootProperty: 'nmts'
                 }
              }
           }
    
        });

Ext.define('myApp.model.SensorStation', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            {
                
                name: 'name', 
                type: 'string',
                mapping: '@name'
                //convert: function (value, record) {
                //    Ext.Msg.alert(value,record.raw);
                //    //var nodes = rec.raw.querySelectorAll('');
                //}
            },
            {
                name: 'lat',
                mapping: '@latitude',
                type: 'float'
            },
            {
                name: 'lng',
                mapping: '@longitude',
                type: 'float'
            },
            {
                name: 'locid',
                mapping:'@locid',
                type: 'string'
            }
        ]
    }
});
halfer
  • 19,824
  • 17
  • 99
  • 186
Franva
  • 6,565
  • 23
  • 79
  • 144

1 Answers1

2

I figured out what's the problem is... I have never worked with XML so,I don't know how the response of ajax request look like ,but by applying following code for store will fill your app's store(just a little change in your code)

Code:

Ext.define('myApp.store.SensorStationStore', {
    extend: 'Ext.data.Store',
    requires: ['myApp.model.SensorStation', 'Ext.data.reader.Xml'],
    config:{
        model: 'myApp.model.SensorStation',
        storeId: 'SensorStore',
        autoLoad: true,
        proxy: {
            type: 'ajax',
            url: 'http://webtrak.bksv.com/mel/configuration',
            //url: 'app/store/configuration.xml',
            reader: {
                type: 'xml',
                record: 'locations',
                rootProperty: 'nmts'
            }
        }
    } });

You are trying to apply store configs outside of config object. Cheers!!

Naitik
  • 105
  • 6
  • Hi @Naitik, thank you for your help. I actually have moved the proxy into the config and still it does't work. I will update the code in my post now. Do you have any ideas about the reason? – Franva Apr 23 '14 at 12:51
  • Actually i made a demo from your code and i'm surprised that with this little change in code has fill the store.If you want to see the demo please let me know.I'll provide you a link from which you can download the demo. – Naitik Apr 23 '14 at 13:12
  • hi @Naitik, yes for sure~!I want to see the demo and I hope it works on my devices as well! Could you please send me the code? thank you. I will be here waiting for your call. It will be great if you could upload your code onto OneDrive then I will be able to get it. – Franva Apr 23 '14 at 13:29
  • 1
    sorry @Franva. I don't have OneDrive account so i'm giving you my [dropbox](https://www.dropbox.com/s/lrz9hvp3gqzqwqi/www.zip).From here you can download the code.Reply will be appreciated. – Naitik Apr 23 '14 at 13:49
  • 1
    Hi Naitik, I cannot deploy your example code onto my device as it's not a Sencha application(got this when trying to deploy it to my device), but never mind. I finally did it by moving the proxy into config in the model(not the store) and thank you for reminding me :) I had been stuck at this problem for a week!!! so I am happy about the result and just want to know what differences could be by putting proxy in model or store. – Franva Apr 23 '14 at 14:03
  • 1
    As per my knowledge...there is a not at all any problem by putting proxy in model or store...but sencha recommended to put proxy within store..you can find out more on sencha documentation...and yea..one more thing...in my demo...you don't have to put on device...just run the index.html in chrome or safari and go in the console by doing inspect element..and that demo is made sencha...(I've not used sencha cmd,may be that's why you get that error) – Naitik Apr 23 '14 at 15:33
  • 1
    hi @Naitik, thank you very much for your explanation. One question: if testing in browsers, how could you get around the CORS issue? That's the reason why I have to test my app in devices. thanks :) – Franva Apr 23 '14 at 23:21
  • 1
    cross-domain issues can be solved by running your browser in disable security mode.If you want to check it out,open Run(Windows) or Terminal(MAC) and run this line(For Google Chrome): For'MAC': open /Applications/Google\ Chrome.app/ --args --disable-web-security For 'Windows': chrome.exe --allow-file-access-from-files --disable-web-security If you succeed, then chrome notify you that you are running your browser in disable security mode.Now you can test your app.Even Chrome provides diff. iOS and Android devices Emulator.So you can have diff.virtual devices for checking your app. – Naitik Apr 24 '14 at 06:55
  • Hi Naitik, Great comment!!!! Now, I can even test it in my browsers!!!! You made my day!!!! – Franva Apr 24 '14 at 12:05