How do I AJAX - Access-Control-Allow-Origin: *

0 favourites
  • 4 posts
From the Asset Store
Supports keyboard, mouse and gamepads. Supports several gamepads at once.
  • I'm trying to pull a large database as a JSON file from a website using the AJAX plug-in.

    I've copied the text bellow from the Construct 2 AJAX Plug-in Reference page in the manual.

    Making AJAX requests cross-domain or in preview:

    "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: *"

    The manual fails to mention how this is executed.

    Exactly how do I configure an AJAX request to send a HTTP header such as "Access-Control-Allow-Origin"

  • You're probably better off using Google for getting info on this as from what I can gather (those who know please feel free to put me right) you will need to configure the server to allow this.

  • Thats why i'm here, I can't find a solution that will allow construct to do this, because construct is whats going to have to send the header wrapped in it's ajax GET request. Realistically I need to have construct send its AJAX GET request with an Authorization key and instruction for the browser to access "cross domain".

    At this stage I'm leaning towards trying to use the XML plug-in instead as I'm assuming you can write your own AJAX GET request will all the information required.

    However I can't see a way to import a JSON file and then populate and array using the imported JSON file data. This is paramount because there are over 100 elements each containing over 30 properties. I am not about to embark on manually populating my array with over 3000 entries which are subject to change at any time.

    The website I've been authorized to pull the data from keeps their database up to date and complete. Using their JSON file is the only way I can build my app and export it to android in a timely and viable manner.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • it's unfortunately not a construct issue but a server issue. from my understanding, the test mode creates a localhost server and the browser pulls from that... however the browser does not allow one server to redirect to another server without a specific command.

    the long term solution is that when you host it, it will pull data from its own servers, and then this issue will not arise.

    however I haven't seen an easy-to-understand solution for testing in development mode. I upload to my server but it is awkward.

    please Ashley.. this is something that should be fixable by Construct for testing purposes.. it would make server/client testing much much easier.

    R

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