How do I load a txt file from my server

0 favourites
  • 7 posts
From the Asset Store
The official Scirra Multiplayer Signalling Server for helping peers find and connect to each other
  • Hi guys. I was reading the manual about AJAX and I didn't get how exactly I should allow cross-domain access so I can load text and image files from my server.

    This "Access-Control-Allow-Origin: *" is used on the server?

    [quote:wpc36sms]

    Making AJAX requests cross-domain or in preview

    By default, browsers block AJAX requests across domains. This means, for example, a game on scirra.com can request other pages on scirra.com, but cannot request pages on facebook.com. This is an important security feature of web browsers (it is not specific to Construct 2 or its AJAX object).

    Also, when previewing in Construct 2 the game runs on localhost. This counts as a different domain to the rest of the internet, so typically AJAX requests to any web page will fail during preview, unless the server explicitly allows cross-domain requests.

    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, but you should still be aware of the possible security implications of this. For more information on cross-domain requests see HTTP access control on MDN.

    Could someone help me?

    Thanks.

  • "Access-Control-Allow-Origin:" Is a setting on your web server (Apache?) where the file you are trying to get is located. If you not managing your own web server config, such as with a third party hosting site, you might not have access to this. You can always try inquiring with your host/server admin to see if it can be enabled.

    ref: https://enable-cors.org/server_apache.html

  • oosyrag So if I have the access can I Just do:

    <?php

    header('Access-Control-Allow-Origin: *');

    'Whatever text I want goes here'

    And so using the php file as a normal text file. Would work?

  • I have no idea. Try it and find out.

  • I'd create a single PHP script that fetch text files and output them. So you don't have to create a new PHP file with "header('Access-Control-Allow-Origin: *');" everytime.

    Also, if the application is hosted on the same server, none of this is necessary.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Magistross The problem is that I have no knowledge at this.

    What I need to do is: everyday I'll update a repository in this server with text and images. I thought about allowing the access to this entire repository because I'm making an app(NW.JS) that will be running in another domain and will get these texts and images.

    Is it simple to do? Could you make an example for me or link some documentation so I could try to do it? ^^

  • Magistross I managed to do it using 000webhost. I uploaded a txt file and changed the permission to read and write for "others". Everything done using their layout. Is it trustable?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)