1. #1
    Sencha User rahul.naik's Avatar
    Join Date
    Mar 2012
    Location
    Mumbai
    Posts
    2
    Vote Rating
    0
    rahul.naik is on a distinguished road

      0  

    Default cross domain Problem while Ajax call

    cross domain Problem while Ajax call


    I am new to Sencha touch.
    i am trying to get content of XML file in list-view.IT works when i create my own XML file and run it on Apache server.But i want data should load from xml file which resides at remote server say www.mysite.com/abc.xml
    When i write above URL in url property and run it on server it gives me cross domain problem.
    is there any solution for this problem? JSONP is one solution that i found on net.But i didn't understand that.
    Is there any other method to solve this problem?

    Ext.setup({
    icon: 'icon.png',
    tabletStartupScreen: 'tablet_startup.png',
    phoneStartupScreen: 'phone_startup.png',
    glossOnIcon: false,
    onReady: function() {


    Ext.regModel('Contact',{
    fields:['title','description','pub_date']
    });


    var storex=new Ext.data.Store({
    model:'Contact',
    proxy: {
    type: 'ajax',
    url : 'http://www.glamsham.com/rss/glamrss_review.xml',
    reader: {
    type: 'xml',
    record: 'item',
    root:'rss'
    }
    }


    });




    listPanel = new Ext.List({
    store: storex,

    itemTpl: '{title} {description}',
    onItemDisclosure: true



    });

    wrapperpanel=new Ext.Panel({
    fullscreen:true,
    items:listPanel,
    dockedItems:[{
    xtype:'toolbar',
    title:'List View'

    }]

    });
    }
    });


    above is my code

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,533
    Vote Rating
    871
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Ajax will not be able to load cross-origin resources. JsonP is the only way but that does not support XML.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    Bangalore, India
    Posts
    13
    Vote Rating
    1
    Nilanchala is on a distinguished road

      0  

    Default Visit this link for details on Cross domain ajax calls

    Visit this link for details on Cross domain ajax calls


    http://objectechenica.blogspot.com/2...me-origin.html
    Nilanchala Panigrahy

  4. #4
    Sencha User rahul.naik's Avatar
    Join Date
    Mar 2012
    Location
    Mumbai
    Posts
    2
    Vote Rating
    0
    rahul.naik is on a distinguished road

      0  

    Default


    Thanks to all...
    I integrated my sencha app with phonegap to run it on android emulator.
    And in my code i directly set url attribute of ajax to the link as shown below and run it on Emulator...

    proxy: {
    type: 'ajax',
    url : 'http://www.glamsham.com/rss/glamrss_review.xml',
    reader: {
    type: 'xml',
    record: 'item',
    root:'rss'
    }
    }
    While dealing with phonegap cross domain problem doesn't occur...
    Does that mean Phonegap is solution for cross domain problem???
    I am bit confused...

  5. #5
    Sencha User
    Join Date
    Jul 2011
    Posts
    4
    Vote Rating
    0
    gmz is on a distinguished road

      0  

    Default


    Yes, in PhoneGap it is possible, native application does have this possibility.
    You can also upload your application to any server, it can be otherweise "real" server, or some localhost emulation like Apache.

    But when you run web app directly from your hard drive - it's not possible to request external servers.

    btw, PhoneGap is also nice way to acces file system by javascript pure web-app cannot do this.

  6. #6
    Sencha User
    Join Date
    Aug 2010
    Posts
    303
    Vote Rating
    3
    steve1964 is on a distinguished road

      0  

    Default


    The reason because cross domain ajax call works on Phonegap it's because with an app you dont have origin domain.In a web app you can do croos domain call, for example by using a php proxy, so you call on the same domain and the php reterun the data from another domain.