[solved] How do I use AJAX correctly cross-domain?

Get help using Construct 2

Post » Sun Apr 13, 2014 8:09 pm

Hi,
I read the manual about AJAX object but I don't understand this completely.
How do I use AJAX to download the content from my website?
I have a php website and write some data with echo and can request this with parameters in url ($_GET["var"]).
Works fine with other dev programs. But with contruct 2 and AJAX browsers block requests across domains.

The manual says:
If you want AJAX requests to your server to work from any domain, or in preview, you can configure it to send the following HTTP header:
Access-Control-Allow-Origin: *

Can you help me, please? Explain with an example?
For the first I just have a text and ajax object. ajax request a url and load the lastdata in the text object.
On the same domain / website its works. But not on localhost or others.

PS: I develop for iOS. And want this feature.
Last edited by DAG on Mon Apr 14, 2014 6:32 pm, edited 1 time in total.
B
13
S
4
G
1
Posts: 107
Reputation: 1,337

Post » Mon Apr 14, 2014 12:58 am

This does only work for standard apache servers.

For nginx, iis etc you need to read more google for providing this feature from other ip's.

rdgs
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Mon Apr 14, 2014 12:08 pm

PHP should have a function to set a response header, and you just need to set the header described in the manual.
Scirra Founder
B
395
S
233
G
88
Posts: 24,376
Reputation: 193,842

Post » Mon Apr 14, 2014 6:17 pm

Ok thx.

Solution:
PHP:
header('Access-Control-Allow-Origin: *');
B
13
S
4
G
1
Posts: 107
Reputation: 1,337

Post » Thu Apr 17, 2014 9:34 pm

Soooo, now I have another nearly same issue. Image! Images have no header. So it can't define as cross domain. But how do I load a image url to a sprite cross domain?
B
13
S
4
G
1
Posts: 107
Reputation: 1,337

Post » Fri Apr 18, 2014 1:40 am

Ok, I think we encountered the similar question.

how-do-i-display-an-image-getting-from-http-get_t101832.
B
37
S
4
G
2
Posts: 45
Reputation: 3,997

Post » Fri Apr 18, 2014 1:47 am

I have a directory that I put all my Construct 2 PHP in. It has this in its .htaccess file and it works just fine.

<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
B
9
S
3
Posts: 37
Reputation: 749

Post » Fri Apr 18, 2014 8:12 am

Thanks but no solution works. :/
@KennyOops:
1. Via php script get the remote image binary datas, and save it to local server as jpg or png etc.
2. Use sprite's Load image from URL to display that image.

I need some source code please.

My server webspace tree:
Folder > Files
root > index.php
root\content > image.png
B
13
S
4
G
1
Posts: 107
Reputation: 1,337


Return to How do I....?

Who is online

Users browsing this forum: David181 and 19 guests