-
21 Sep 2010 5:57 AM #1
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.
The error I get is: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 },
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.)
-
21 Sep 2010 6:07 AM #2
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
21 Sep 2010 6:10 AM #3
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"?
-
21 Sep 2010 6:21 AM #4
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!
-
21 Sep 2010 6:47 AM #5
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
-
21 Sep 2010 11:04 AM #6
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
-
31 Oct 2010 6:56 AM #7
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)
-
16 Nov 2010 8:57 AM #8
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 }
-
16 Nov 2010 9:01 AM #9
'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).
-
16 Nov 2010 9:13 AM #10
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
-
Ajax call cross domain
By dbottillo in forum Sencha Touch 1.x: DiscussionReplies: 12Last Post: 16 Sep 2010, 2:41 AM -
Ajax.request from outside domain
By mitchellsimoens in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 10 Aug 2010, 4:06 AM -
Cross Domain Ajax?
By cgp in forum Community DiscussionReplies: 2Last Post: 6 Oct 2008, 4:55 AM -
AJAX Cross Domain
By ameikle in forum Ext 1.x: Help & DiscussionReplies: 6Last Post: 12 Jan 2007, 1:03 PM


Reply With Quote



