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

  • 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.

  • 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

  • PHP should have a function to set a response header, and you just need to set the header described in the manual.

  • Ok thx.

    Solution:

    PHP:

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

  • 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?

  • Ok, I think we encountered the similar question.

    .

  • 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>

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks but no solution works. :/

    KennyOops:

    [quote:2x8brscn]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

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