This is the first time ever I’m using AJAX, and I want to do the following on an otherwise static page http://www.xyz.org/some_site.html:
- Send a GET request to another url
"www.xyz.org/testscript" - if response has either
status code != 200orcontent != 'ok': do nothing - else: include sth on the website (i.e. set
style="display:block"on an element that previously had"display:none")
I’ve implemented that successfully using basic AJAX. But:
There is an Apache redirect installed pointing from www.xyz.org/testscript to subdomain.xyz.org/testscript, the URL where the actual testscript lives (as AJAX doesn’t support cross-domain calls even to subdomains afaik).
When I call http://www.xyz.org/testscript I get a 302 status code, and the content says “The document has moved here: subdomain.xyz.org/testscript”.
How can I grab the ‘final’ return value?
I guess/hope any AJAX expert can give me a one-liner to solve that …
AJAX (or XMLHttpRequest to be acurate) won’t be tricked by a redirect. To be able to get content from another domain you need to use a proxy on the server. The following is a simple PHP proxy:
use it like this: