1. #1
    Ext JS Premium Member
    Join Date
    Jul 2010
    Posts
    234
    Vote Rating
    1
    DaveC426913 is on a distinguished road

      0  

    Default Ajax domain issues

    Ajax domain issues


    I don't know here else to turn. I'm out of my league on this Ajax stuff and no amount of research is pointing toward a solution.

    I am trying to populate my list with a call to my server that is going to deliver some XML. First step is to get a session ID.

    My page is choking on the cross-domain request before it ever gets to the server.

    Code:
     
      Ext.Ajax.request({
       url: 'http://server-s01.mydomain.com:81/ws/srnStoreDeviceSessionServices.php',
                method: 'POST',
                params :{fun:'srnDeviceLogin',did:'66:66:00:00:00:EE'},
       success: function(response, opts) {
         //do some successful stuff
       }
       failure: function(response, opts) {
         //complain
       },
    The error I get is:
    XMLHttpRequest cannot load http://server-s01.mydomain.com:81/ws/srnStoreDeviceSessionServices.php. Origin http://comp-013.mydomain.com:8080 is not allowed by Access-Control-Allow-Origin.

    I know the call is correct; I can do a wget at the commandline at it returns the XML I want.
    wget -O session.xml --post-data="fun=srnDeviceLogin&did=66:66:00:00:00:EE" http://server-s01.mydomain.com:81/ws/srnStoreDeviceSessionServices.php


    I've tried playing with document.domain:
    document.domain="server-s01.mydomain.com";

    I just get a different flavour of the same error:
    Uncaught Error: SECURITY_ERR: DOM Exception 18

    I've researched every angle I can think of to no avail. (And, as mentoined I'm a little out of my league with server-side stuff.)

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,996
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Ext JS Premium Member
    Join Date
    Jul 2010
    Posts
    234
    Vote Rating
    1
    DaveC426913 is on a distinguished road

      0  

    Default


    But we had this working. I've got a demo that performed using jquery. That was before we changed our servers. Now I can't prove it was working.

    What about this document.domain thing? I don't really undetrstand how that might be applicable to my setup.

    Do I simply say: document.domain="mydomain.com"?

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,996
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    You can't do cross domain Ajax requests (this is in general). The best you can do is JSONP: http://remysharp.com/2007/10/08/what-is-jsonp/
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Sencha Premium Member danguba's Avatar
    Join Date
    Feb 2009
    Location
    Kragujevac, Serbia
    Posts
    377
    Vote Rating
    28
    danguba will become famous soon enough danguba will become famous soon enough

      0  
    All Best
    ---
    Željko Mitrović
    http://skitanja.blogspot.com/

    "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." Martin Golding

  6. #6
    Ext JS Premium Member
    Join Date
    Jul 2010
    Posts
    234
    Vote Rating
    1
    DaveC426913 is on a distinguished road

      1  

    Default


    Got it!

    My back-end guy modified the server to provide domain access, thus:

    # go to where the Apache source files are located
    cd /usr/local/src/httpd-2.2.9/modules/metadata/

    # compile the header handling functions
    sudo /usr/local/apache2/bin/apxs -c mod_headers.c

    # link them into Apache
    sudo /usr/local/apache2/bin/apxs -i -a -n headers .libs/mod_headers.so

    # open the configuration file
    sudo -e /usr/local/apache2/conf/httpd.conf

    # add these lines after the htdocs directory section
    <Directory "/usr/local/apache2/htdocs/ws">
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "GET,POST"
    Header set Access-Control-Allow-Headers "x-prototype-version,x-requested-with"
    </Directory>

    # restart Apache so that the new changes take effect
    sudo /usr/local/apache2/bin/apachectl -k restart

  7. #7
    Ext User
    Join Date
    Oct 2010
    Posts
    9
    Vote Rating
    0
    iffius is on a distinguished road

      0  

    Default


    Quote Originally Posted by evant View Post
    You can't do cross domain Ajax requests (this is in general). The best you can do is JSONP: http://remysharp.com/2007/10/08/what-is-jsonp/
    That's not correct for most modern browsers. You can do cross domain Ajax request with CORS (Cross-Origin Resource Sharing). See http://www.nczonline.net/blog/2010/0...ource-sharing/ for more info.

    Unfortunately, this seems to be broken with Ext.ajax.request() infrastructure. Although a simple cross domain ajax request works, the Ext one fails with an unhelpful error code 0. I think root cause is that Ext is mucking with the request causing an invalid state (at least with regard to making a cross domain request)

  8. #8
    Sencha User
    Join Date
    Apr 2010
    Posts
    55
    Vote Rating
    0
    cavalleydude is on a distinguished road

      0  

    Default


    Hi DaveC426913,

    Regarding the Apache configuration changes made above, did this allow your Ext.Ajax.request (below) to work okay? Does the web service you call return JSONP format, or standard JSON? I do not see a callback, so I;m assuming you are making this work without JSONP and callbacks, right?

    -cavalleydude

    Code:
      Ext.Ajax.request({
       url: 'http://server-s01.mydomain.com:81/ws/srnStoreDeviceSessionServices.php',
                method: 'POST',
                params :{fun:'srnDeviceLogin',did:'66:66:00:00:00:EE'},
       success: function(response, opts) {
         //do some successful stuff
       }
       failure: function(response, opts) {
         //complain
       }
    Quote Originally Posted by DaveC426913 View Post
    Got it!

    My back-end guy modified the server to provide domain access, thus:

    # go to where the Apache source files are located
    cd /usr/local/src/httpd-2.2.9/modules/metadata/

    # compile the header handling functions
    sudo /usr/local/apache2/bin/apxs -c mod_headers.c

    # link them into Apache
    sudo /usr/local/apache2/bin/apxs -i -a -n headers .libs/mod_headers.so

    # open the configuration file
    sudo -e /usr/local/apache2/conf/httpd.conf

    # add these lines after the htdocs directory section
    <Directory "/usr/local/apache2/htdocs/ws">
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "GET,POST"
    Header set Access-Control-Allow-Headers "x-prototype-version,x-requested-with"
    </Directory>

    # restart Apache so that the new changes take effect
    sudo /usr/local/apache2/bin/apachectl -k restart

  9. #9
    Ext JS Premium Member
    Join Date
    Jul 2010
    Posts
    234
    Vote Rating
    1
    DaveC426913 is on a distinguished road

      0  

    Default


    Quote Originally Posted by cavalleydude View Post
    Hi DaveC426913,

    Did this allow your Ext.Ajax.request (below) to work okay? Does the web service you call return JSONP format, or standard JSON?
    'Yes' and 'I don't know', respectively. (Actually, yes I do, It was returning XML; I had to convert it.)

    Fortunately or unfortunately, depending on your philosophy, that whole system (hardware and API) is nearing end-of-life, so no more support. We are building a shiny new db and API. It will use JSON (or JSONP, I don't know the diff yet).

  10. #10
    Sencha User
    Join Date
    Apr 2010
    Posts
    55
    Vote Rating
    0
    cavalleydude is on a distinguished road

      0  

    Default


    Okay, I'll try it. The whole cross-domain issue seems like it trips up lots of people. I've not seen a discussion that fully describes how to implement it. In fact, since all my supposedly "cross domain" calls are really "same domain" (between different hosts, but the same domain [ie. mycompany.com] ), it seems like the Apache change may be the right solution in this instance. I'll try it.

    Thanks Dave!

Similar Threads

  1. Ajax call cross domain
    By dbottillo in forum Sencha Touch 1.x: Discussion
    Replies: 12
    Last Post: 16 Sep 2010, 2:41 AM
  2. Ajax.request from outside domain
    By mitchellsimoens in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 10 Aug 2010, 4:06 AM
  3. Cross Domain Ajax?
    By cgp in forum Community Discussion
    Replies: 2
    Last Post: 6 Oct 2008, 4:55 AM
  4. AJAX Cross Domain
    By ameikle in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 12 Jan 2007, 1:03 PM

Thread Participants: 5