I
I
IvanOne2016-01-14 08:57:32
JavaScript
IvanOne, 2016-01-14 08:57:32

What about cross-domain ajax requests?

Good afternoon! There is a project on django as well as two servers that give information about the status of networks and servers. Almost all requests come from js, that is, from the client, the servers are on the same domain, but on different ports. Right now everything is running with errors like Single Origin Policy prohibits reading remote resource on (Reason: CORS header 'Access-Control-Allow-Origin' is missing). Actually, there are two ways, either to do proxying through django, that is, all requests will go through python (not a very good option). Or finish js with some kind of library for such requests. Actually, your opinion is interesting, which is better, and if you take the second option, which library is better? Or is it possible to get by with adding headers altogether? ps The jquery library is also connected

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexander, 2016-01-14
@bIbI4k0

Add headers at the web server level, specifying the host from which you pull the data as trusted. :)

V
Vladimir, 2016-01-14
@vintello

score on cross-domain at the browser level and lead all requests from js to one server. let this server provide interactions

J
Justique, 2016-01-14
@Justique

jquery jsonp

X
xmoonlight, 2016-01-14
@xmoonlight

https://learn.javascript.ru/xhr-crossdomain

V
VZVZ, 2016-01-14
@VZVZ

> make proxying through django, that is, all requests will go through python (not a very good option).
Why not very good?
If there is MVC, then simply create a new Action in the controller, inside which you make a request, and return the response to this request. Everything.
> Or finish js with some kind of library for such requests
. Where did you see this?
Libraries are just wrappers for pure JS that make it easier to work with but don't add any new functionality.
What is impossible on raw JS, there are no libraries for that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question