Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax cross domain on same machine but different port

We have a set of api that we're calling from the same machine, the address is mycompany.com:8080 for the server and mycompany.com for the ajax.html file.

How can we avoid the cross domain policy?

Anyway to do this with some proxy configuration?

please, no JSONP!

Thanks!

like image 525
Enrichman Avatar asked Jul 10 '12 11:07

Enrichman


2 Answers

You ask if this can be done with a proxy configuration, and of course that's one simple solution, just have the main server proxy requests to the AJAX server. It's usually simple to set up. But the Same Origin Policy means that you won't be able to do this with a pure client-side solution.

like image 39
Scott Sauyet Avatar answered Oct 17 '22 06:10

Scott Sauyet


Two or more documents can be considered in same domain origin, if they have on - Same Host - Same Port - Same Protocol. In your case port is different so you can not put ajax query directly. Instead you need to specify following header in response.

 Access-Control-Allow-Origin: mycompany.com 

For more info, check this

like image 109
Laxmikant Dange Avatar answered Oct 17 '22 08:10

Laxmikant Dange