Answer the question
In order to leave comments, you need to log in
How to make an AJAX request from one subdomain to another?
Hello.
I am somewhat behind the times and modern technologies and I am trying to understand: is it possible in 2014 to make an Ajax request from one of my subdomains to another?
Browsers are modern, there is full control over subdomains (including headers).
Hacks with iframes, jsonp, images with get parameters, etc. I know perfectly well. So the question is only about AJAX and CORS.
Thank you.
Answer the question
In order to leave comments, you need to log in
So you wrote everything correctly, we use CORS, we give the Access-Control-Allow-Origin header.
For example, in PHP:
script.php:
<?php
header('Access-Control-Allow-Origin: *');
echo 'Hello!';
?>
$(function() {
$.get('http://example.com/script.php', function(data) {
alert(data); // Hello!
});
});
No, but this is "not a bug, but a feature."
You are prohibited by default from processing requests from third-party resources. This allows you to protect yourself from processing requests for processing forms (for example) from the left server. Eliminates various stupid hacking possibilities like brute force, etc.
This will not be fixed because there is nothing to fix.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question