Error: Origin is not allowed by Access-Control-Allow-Origin

HTML5-based JavaScript library for building mobile web applications
Hello,
i'm trying to retrive a xml from an url, to do that i wrote the following lines
Code: Select all
dhx.ajax("http://192.168.2.80:8089/EdicomStuffServer/services/OutsmonRest/getDomains/username/prueba/password/prueba/", function(text){
   var txt=text;
   alert(text);
});

inspecting the document with firebug the txt variable is an empty string and I also get the error:
Code: Select all
XMLHttpRequest cannot load http://192.168.2.80:8089/EdicomStuffServer/services/OutsmonRest/getDomains/username/prueba/password/prueba/. Origin http://127.0.0.1:8020 is not allowed by Access-Control-Allow-Origin

I also tried with others urls and I get the same error.
(I'm using aptana as IDE and I tried both the embedded web server and apache web server to run the mobile application).
Do you know how I can resolve this problem?

thanks
Danilo
danilodelizia
 
Posts: 18
Joined: Thu Oct 20, 2011 1:45 pm

Is the main html page also loaded from the same url - http://192.168.2.80:8089 ?
Otherwise browser will block data loading because of cross domain security
( you can configure headers in server's response to allow cross domain request for FF and WebKit browsers )
Stanislav
 
Posts: 9652
Joined: Wed Dec 23, 2009 3:04 pm

Thanks Stanislav for your response,
the html is loaded from 127.0.0.1, that is why I'm getting thi error. I serched on google and I saw that making a request with "Access-Control-Allow-Origin 127.0.0.1" I can bypass the problem, so my question is how can I make a request with that parameter Access-Control-Allow-Origin 127.0.0.1 with dhtmlx framework?

The current header that is generating is the following:
Code: Select all
Request URL:http://192.168.2.80:8089/EdicomStuffServer/services/OutsmonRest/getDomains/username/prueba/password/prueba/
Request Headersview parsed
GET http://192.168.2.80:8089/EdicomStuffServer/services/OutsmonRest/getDomains/username/prueba/password/prueba/ HTTP/1.1

Origin: http://127.0.0.1:8020

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2

Referer: http://127.0.0.1:8020/mobile-mon/index.html


As you commented in your answer do you think if I make the same above request and the server put in the response headers the parameter:
Access-Control-Allow-Origin 127.0.0.1
it is going to work?

Thanks again for your advices
Greetings
Danilo
danilodelizia
 
Posts: 18
Joined: Thu Oct 20, 2011 1:45 pm

That must be the header in the response, not in the ajax call.
In case of apache - you can add instructions to output such header through .htaccess file

http://enable-cors.org/
Stanislav
 
Posts: 9652
Joined: Wed Dec 23, 2009 3:04 pm


Return to DHTMLX Touch

Who is online

Users browsing this forum: No registered users and 121 guests