Reading text from a .txt file on the internet.

Get help using Construct 2

Post » Wed Jan 11, 2012 11:16 pm

Does anyone know of a way to read text into a string from a .txt file stored on the internet?

The idea is to be able to dynamically change strings (holding information) in a game posted on many different web sites without having to manually change the strings and then re-upload the game to all the websites it is hosted on. If I could pull the information to be displayed in the strings from the internet all I would have to do is change the .txt file containing the information on the internet and this would change all the games on the internet.

Jason
B
18
S
7
G
5
Posts: 62
Reputation: 4,410

Post » Wed Jan 11, 2012 11:25 pm

I guess you can look for XMLHttpRequest...septeven2012-01-11 23:26:01
B
44
S
12
G
13
Posts: 628
Reputation: 10,471

Post » Wed Jan 11, 2012 11:26 pm

Yes it's possible. I remember @Yann posting a example of doing this. I don't remember how he did it though. Most likely through Ajax. You can waif for him to read this thread or play with Ajax
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Wed Jan 11, 2012 11:26 pm

It's possible with ajax, but ajax works on the same domain the page is on.
Won't work to call .txt from other domains.

dialog.capx
Works fine here
http://dl.dropbox.com/u/23551572/C2-Gam ... index.html
But I'm pretty sure it won't work if you export the .capx in your own webhost.
Last edited by Yann on Sun Sep 14, 2014 10:11 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Jan 12, 2012 2:50 am

Would XMLHttpRequest work cross domain? What ever is used has to work cross domain.

Jason
B
18
S
7
G
5
Posts: 62
Reputation: 4,410

Post » Tue Aug 07, 2012 7:28 pm

[QUOTE=Yann] It's possible with ajax, but ajax works on the same domain the page is on.
Won't work to call .txt from other domains.

http://dl.dropbox.com/u/23551572/C2/externalFile/dialog.capx
Works fine here
http://dl.dropbox.com/u/23551572/C2-Games/dialog/index.html
But I'm pretty sure it won't work if you export the .capx in your own webhost.[/QUOTE]

Yann, sorry to bore you, but it's common to fail when in preview mode?

After editing the source file link

Your capx is returning fail even if exporting it with the pre-configured address..

https://dl.dropbox.com/u/47035927/temp/multi_language_test/index.html

Edited: the issue was caused by caching it with the first try ^^

So! People who is wondering use it, edit the TXT link before exporting it, if you export it before editing it, clear your Cache.TELLES08082012-08-07 20:00:01
ImageImageImageImageImageImage
B
93
S
20
G
13
Posts: 1,217
Reputation: 18,996

Post » Tue Aug 07, 2012 9:06 pm

well now we should use the import files features of c2 so that it will work in preview mode.
The preview mode doesn't work because because browsers or server (I don't remember) block ajax's cross domain requests unless the server sends header that allow it.
But using the import files, the files are exported when preview in the same place as the script and accessible via localhost.
Should update my old capx maybe...
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Aug 07, 2012 10:20 pm

The cross-domain AJAX restrictions and how to work around them (including in preview mode) are described in the AJAX manual entry.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Tue Aug 07, 2012 11:30 pm

[QUOTE=Yann] well now we should use the import files features of c2 so that it will work in preview mode.
The preview mode doesn't work because because browsers or server (I don't remember) block ajax's cross domain requests unless the server sends header that allow it.
But using the import files, the files are exported when preview in the same place as the script and accessible via localhost.
Should update my old capx maybe...[/QUOTE]

Thx buddy!

[QUOTE=Ashley] The cross-domain AJAX restrictions and how to work around them (including in preview mode) are described in the AJAX manual entry.[/QUOTE]

Ashley, I had read the "Access-Control-Allow-Origin: *" on the manual, but still not figuring out how to configure it to send the following HTTP header.

I tried these steps, with the conditional "When in preview":
- Writing it on the first line of the txt;
- Posting, with Ajax, "Access-Control-Allow-Origin: *" to "Localhost";

Stupid tries, no idea of what I'm doing =\
ImageImageImageImageImageImage
B
93
S
20
G
13
Posts: 1,217
Reputation: 18,996


Return to How do I....?

Who is online

Users browsing this forum: SpartCrafter and 19 guests