Results 1 to 2 of 2

Thread: RESTful request gets "403: No Access-Control-Allow-Origin" Error

  1. #1
    Sencha User
    Join Date
    Jun 2017
    Posts
    25
    Answers
    2

    Default RESTful request gets "403: No Access-Control-Allow-Origin" Error

    Hi to all,

    I am building a sample app through "Enterprise Application Development with Ext JS and Spring" book and getting data from another computer (calling as: httpIP:port/dbname/table.json")

    The error exists during fetching data to grid:

    Code:
    "Failed to load resource: the server responded with a status of 403 ()"
    Code:
    XMLHttpRequest cannot load http://ip:port/db/agency.json?_dc=1500380014131&page=1&start=0&limit=25. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 403.
    According to book, i have created all Java-Spring side well and i can reach the json file via URL but when the time is ripe to display on sample app, the error above is come up.

    Here is code block:

    Main.js
    * A viewport defined and Grid panel inside it with 5 columns -all view side is work well-

    MainStore.js
    Code:
    Ext.define('MyApp.store.MainStore', {
        extend: 'Ext.data.Store',
        requires: ['MyApp.model.MainModel'],
        model: 'MyApp.model.MainModel',
        proxy: { 
            type: 'ajax', 
            url: 'http://ip:port/db/agency.json',
            reader: {
                type: 'json'
            }
        },
        autoLoad: true
    });
    MainModel:
    Code:
    Ext.define('MyApp.model.MainModel', {
        extend: 'Ext.data.Model',
    
        fields: [
            {name: 'id', type: 'int'},
            {name: 'refno', type: 'int'},
            {name: 'usercode', type: 'string'},
            {name: 'resdefinitid', type: 'int'},
            {name: 'langcode', type: 'string'}        
        ],
        
        idProperty: 'id',
        proxy: {
            type: 'ajax',
            idParam: 'id',
            api: { 
                read: 'http://ip:port/db/agency.json'
            },
            reader: {
                type: 'json'
            }
        }
    });
    The JSON file seems like that:
    Code:
    [
    {"id": 1183,"refno": "1183","usercode": "User","resdefinitid": 0000,"email": "[email protected]","isActive": true,
    "tel2": 1111,"mobiletel": 5555,"pricecurr": "TL",
    "city": "City","country": "CountryOne","langcode": "EN"
    }]

    What i am missing here or what i should care/pay attention?

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Sounds like a cross-domain error. Is the IP address in your proxy URL different from the one used by the application? Have you looked at JSONP?
    http://docs.sencha.com/extjs/6.5.1/c...oxy.JsonP.html

Similar Threads

  1. Origin http://localhost is not allowed by Access-Control-Allow-Origin
    By zied jouini in forum Sencha Touch 1.x: Q&A
    Replies: 9
    Last Post: 23 Jun 2013, 9:23 PM
  2. Replies: 4
    Last Post: 30 Apr 2012, 8:05 AM
  3. Replies: 2
    Last Post: 15 Jan 2012, 9:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •