5?????1????5??????

????: Access-Control-Allow-Origin

  1. #1
    Sencha User
    ????
    Apr 2011
    ???
    2
    Vote Rating
    0
      0  

    Question Access-Control-Allow-Origin

    XMLHttpRequest cannot load http://xyz. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

    I get this Exception in my Chrome Browser.

    The server I run is Apache (XAMPP).

    How can I fix this? What can I do?

    Thank you very much

    My Source Code:

    <script type="text/javascript">

    new Ext.Application({

    name: 'Hello World',

    launch: function() {



    Ext.Ajax.request({

    url: 'http://xyz',

    method: 'GET',

    headers: {'Authorization': 'Basic GVU0IXZ6cFGzczE='},

    success: function(response, opts) {

    var obj = Ext.decode(response.responseText);

    console.dir(obj);

    },

    failure: function(response, opts) {

    console.log('server-side failure with status code ' + response.status);

    }

    });



    }

    });

    </script>

  2. #2
    Sencha User
    ????
    Nov 2010
    ??
    Norway
    ???
    56
    Vote Rating
    2
      0  

    ?????

    Take a look as JSONP and ScriptTagProxy. Also read this wiki page: http://en.wikipedia.org/wiki/Same_origin_policy.

  3. #3
    Sencha User
    ????
    Aug 2010
    ??
    Europa
    ???
    216
    Vote Rating
    1
      0  

    ?????

    Or you can use a PHP proxy

  4. #4
    Sencha User
    ????
    Sep 2011
    ???
    8
    Vote Rating
    0
      0  

    ?????

    ?? aCa???????? ?????
    Take a look as JSONP and ScriptTagProxy. Also read this wiki page: http://en.wikipedia.org/wiki/Same_origin_policy.

    I think he is right. You should probably try Ext.util.JSONP.request() instead and see if that works out for you

  5. #5
    Sencha - Services Team AndreaCammarata's Avatar
    ????
    Jun 2009
    ??
    Italy
    ???
    1,395
    Vote Rating
    24
      0  

    ?????

    ?? Racon???????? ?????
    XMLHttpRequest cannot load http://xyz. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

    I get this Exception in my Chrome Browser.

    The server I run is Apache (XAMPP).

    How can I fix this? What can I do?

    Thank you very much

    My Source Code:

    <script type="text/javascript">

    new Ext.Application({

    name: 'Hello World',

    launch: function() {



    Ext.Ajax.request({

    url: 'http://xyz',

    method: 'GET',

    headers: {'Authorization': 'Basic GVU0IXZ6cFGzczE='},

    success: function(response, opts) {

    var obj = Ext.decode(response.responseText);

    console.dir(obj);

    },

    failure: function(response, opts) {

    console.log('server-side failure with status code ' + response.status);

    }

    });



    }

    });

    </script>
    Hi Racon.
    If you are trying to get data from a domain that is not your businness you have to use JSONP due to the same origin policy.
    However, If you are developing an application on localhost that you will upload on the same domain you are trying to get data from, you don't need to use JSONP!
    In this case you only need to open you application from file://.... intead of http://localhost/...
    This will makes the trick and will allow you to get data from a different domain.

    Hope this helps.
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


Tags for this Thread

?????

  • ???????????????????
  • ????????????
  • ???????????????????
  • ?????????????
  •