How do I CORS?

Get help using Construct 2

Post » Fri Sep 25, 2015 4:28 pm

Example:

Image

I manualy enable CORS in Browser

Image


result:

Image


Manual wrote: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: *

This will enable AJAX requests from any domain....


Please...can someone explain to me ...slowly... how to do this from C2?
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Fri Sep 25, 2015 4:46 pm

You don't do anything from C2, you configure your server to return a response header with "Access-Control-Allow-Origin: *".

This should help : http://enable-cors.org/server.html
B
75
S
31
G
27
Posts: 1,012
Reputation: 20,759

Post » Fri Sep 25, 2015 5:32 pm

[email protected] ...you you're talking about
When Site A tries to fetch content from Site B, Site B can send an Access-Control-Allow-Origin response header to tell the browser that the content of this page is accessible to certain origins. (An origin is a domain, plus a scheme and port number.) By default, Site B's pages are not accessible to any other origin; using the Access-Control-Allow-Origin header opens a door for cross-origin access by specific requesting origins.

this part..let's say...I understand :?

But ..This part in Manual confuses me...
Manual wrote: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: *

This will enable AJAX requests from any domain....


so..if i want Cors to work in preview(on localhost:50000)
like this:

Image

What i need to configure?
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Fri Sep 25, 2015 6:26 pm

The server(s) you will be trying to reach with AJAX request.
B
75
S
31
G
27
Posts: 1,012
Reputation: 20,759

Post » Fri Sep 25, 2015 6:36 pm

Image
Thanks! :?
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Fri Sep 25, 2015 6:52 pm

If you are fetching a server side scripted page, you could also just modify the request there by appending the header.
B
75
S
31
G
27
Posts: 1,012
Reputation: 20,759

Post » Fri Sep 25, 2015 9:05 pm

Magistross wrote:If you are fetching a server side scripted page, you could also just modify the request there by appending the header.


Image

NOT!!!! :cry:
Sorry, I not following you..


to try one more time.....is it possible in C2 (via Ajax,Browser executeJs,jQuery...)
set Access-Control-Allow-Origin: *

...................is it possible to Browsers(Chrome,IE,FF,Opera..) to access data from some site in previw..
(like NW.js):

Image


..If Not..................Thank you very much!

if Yes.....................and you want to help me..
.................................................................................Please, Exacly How?(Screenshot & Capx)

Thank You!
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat Sep 26, 2015 12:38 am

https://www.scirra.com/tutorials/61/aja ... onstruct-2 does this helps? has parts where u can call data from php and send data to a php file... not sure if u mean this, never played with ajax

here is the capx inside the tutorial above ZIP DOWnload

some other stuff for highscores and Stuff

those memes bruh... hilarious
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,025

Post » Sat Sep 26, 2015 7:13 pm

I'm reading...I'm learning.... :geek:

I convinced myself that C2 has some kind of super power...

i have Browser object and i have AJAX...
so ..what is easier... than:

On start of layout....Browser disable Same-origin policy

Or

On start of layout...Browser...-disable-web-security -–allow-file-access-from-files

Thanks!
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sat Sep 26, 2015 7:52 pm

If it was that easy for an application to bypass such an important server security then surely that would make the whole concept of CORS pointless, surely.

A server has to be setup to allow CORS first. It seams to me that you want to set CORS from C2 which doesn't make sense.

This is just my understanding and may obviously be in error.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,540
Reputation: 60,424

Next

Return to How do I....?

Who is online

Users browsing this forum: max2612 and 5 guests