1. #1
    Ext User
    Join Date
    Jul 2010
    Posts
    57
    Vote Rating
    1
    konki_vienna is on a distinguished road

      0  

    Default Reader Example Error

    Reader Example Error


    When I try to copy and paste the Reader-Example of the new ReleaseCandidate I get an error:

    PHP Code:
    XMLHttpRequest cannot load file:///Users/konstantin_d/Sites/SenchaTouch/CustomProjects/sports_book_tablet/users.json?_dc=1289295120215&_dc=1289295120216&page=&start=&limit=25&group=%5Bobject%20Object%5D&filters=&sorters=. Origin null is not allowed by Access-Control-Allow-Origin.sencha-touch-debug-w-comments.js:10636Uncaught TypeError: Cannot read property 'length' of undefined 
    My code is:
    PHP Code:
    Ext.setup({
      
    icon'rsc/img/icon.png',
      
    glossOnIconfalse,
      
    tabletStartupScreen'rsc/img/tabletStartScreen.png',
      
      
    /**
       * This function is automatically called when the document has finished loading.
       */ 
      
    onReady: function() {
            
            
    Ext.regModel("User", {
                
    fields: [
                    
    'id''name'
                
    ],
            
                
    hasMany: {model'Order'name'orders'},
            
                
    proxy: {
                    
    type'rest',
                    
    url 'users.json',
                    
    reader: {
                        
    type'json',
                        
    root'users'
                    
    }
                }
            });

            
    Ext.regModel("Order", {
                
    fields: [
                    
    'id''total'
                
    ],
            
                
    hasMany  : {model'OrderItem'name'orderItems'associationKey'order_items'},
                
    belongsTo'User'
            
    });
            
            
    Ext.regModel("OrderItem", {
                
    fields: [
                    
    'id''price''quantity''order_id''product_id'
                
    ],
            
                
    belongsTo: ['Order', {model'Product'associationKey'product'}]
            });
            
            
    Ext.regModel("Product", {
                
    fields: [
                    
    'id''name'
                
    ],
            
                
    hasMany'OrderItem'
            
    });
            
            var 
    store = new Ext.data.Store({
                
    model"User"
            
    });
            
            
    store.load({
                
    callback: function() {
                    
    //the user that was loaded
                    
    var user store.first();
            
                    
    console.log("Orders for " user.get('name') + ":")
            
                    
    //iterate over the User's Orders
                    
    user.orders().each(function(order) {
                        
    console.log("Order ID: " order.getId() + ", which contains items:");
            
                        
    //iterate over the Order's OrderItems
                        
    order.orderItems().each(function(orderItem) {
                            
    //we know that the Product's data is already loaded, so we can use the synchronous getProduct
                            //usually, we would use the asynchronous version (see Ext.data.BelongsToAssociation)
                            
    var product orderItem.getProduct();
            
                            
    console.log(orderItem.get('quantity') + ' orders of ' product.get('name'));
                        });
                    });
                }
            });
      }    
        
        
    }); 
    Any suggestion what I did wrong? (The user.json-file is located/stored correctly).

  2. #2
    Ext User
    Join Date
    Jul 2010
    Posts
    57
    Vote Rating
    1
    konki_vienna is on a distinguished road

      0  

    Default


    The example is in the kitchen sink. So I will probably get it to work!

  3. #3
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    You need to serve your app from a web server like apache for it to work. It sounds like the address in your browser starts with file://, which won't allow you to make ajax requests. The easiest way to get this set up on windows is to use WAMP (Windows Apache MySql PHP), or if you're on OS X you already have apache installed. Once you have that set up this will work for you.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  4. #4
    Ext User
    Join Date
    Jul 2010
    Posts
    57
    Vote Rating
    1
    konki_vienna is on a distinguished road

      0  

    Default


    Thanx, this was very helpful. I managed to load local stored data as in the kitchen sink example.

    But what if the url I want to load the json from is not 'users.json' but 'https://mydomain.com/search/search?q=category:live_events%20AND%20gameonline:true'?
    When I enter this url I get an error again:

    PHP Code:
    XMLHttpRequest cannot load https://mydomain.com/search/search.json?q=category%3Alive_events%20AND%20gameonline%3Atrue&_dc=1289300262367&_dc=1289300262368&page=&start=&limit=25&group=%5Bobject%20Object%5D&filters=&sorters=. Origin null is not allowed by Access-Control-Allow-Origin.sencha-touch-debug-w-comments.js:10636Uncaught TypeError: Cannot read property 'length' of undefined 

  5. #5
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    You're running up against the browser's cross domain policy - you can't make AJAX requests to other domains because it's very insecure. The only real way to get around this is using JSON-P, which we have support for with Ext.data.ScriptTagProxy. I suggest you research JSON-P a little before going further, as it works a little differently to normal AJAX calls.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  6. #6
    Sencha User
    Join Date
    Mar 2012
    Posts
    2
    Vote Rating
    0
    vasanth26 is on a distinguished road

      0  

    Default


    i having the same problem im using xml im getting "origin null is not allowed by access-control-allow-origin." im using local xml file as data store. type: 'ajax' in store.

    var store = Ext.create('Ext.data.Store', {
    model: 'Book',
    autoLoad: true,
    proxy: {
    // load using HTTP
    type: 'scripttag',
    url: 'xmlgenerated.xml',
    // the return will be XML, so lets set up a reader
    reader: {
    type: 'xml',
    record: 'Day',
    idProperty: 'Date',
    totalRecords: '@total'
    }
    }
    });

Similar Threads

  1. xml reader error
    By mshepherd in forum Sencha Touch 1.x: Discussion
    Replies: 14
    Last Post: 14 Oct 2010, 4:13 AM
  2. Error with Feed Reader
    By Denis49 in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 15 Jul 2009, 11:10 PM
  3. BasicForm with xml error reader: default error message displayed
    By michele.segata in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 10 Jan 2009, 6:27 AM
  4. array reader error
    By michaelc in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 7 May 2008, 11:08 AM

Thread Participants: 2