AJAX.Lastdata Problem

0 favourites
  • 15 posts
  • Hello -

    I am still very new to construct2.

    I have a very simple php file on my server that does the following:

    <?php

    echo "it works";

    ?>

    Now for construct2 I have a single layout with a text object called "Text" that has a default text of "waiting".

    My event sheet is:

    • System->On start of layout-> AJAX.Request "http://mysite.com/test.php"
    • AJAX->On Complete->Text->Set text to ->AJAX.Lastdata
    • AJAX->On Error->Text->Set text to ->"Error"

    No matter what I am getting an error.

    Please note that I have had 100% success with adding data to mysql through php that originates in construct2... the problem I am getting is receiving data back from php on my server (with or without placing the files on my server).

    Any ideas?

    Thanks.

  • Have you seen the section in the manual about cross-domain or preview AJAX requests? Is that relevant?

  • Yes... I am running my files on my own server so there should not be an issue there... please note though that I have been able to historically make this work, but I recently upgraded to construct version r81.

    A bug maybe? Sending data to php is still not a problem... my php will even update mysql tables with no issue.

    Its just trying to load player data from php. I decided to drop the complexities of tokenat, etc and attempt to just make a simple project that will simply indicate that the receiving of data works. Not working, but I hope I am not missing anything... that would be embarrassing. LOL

  • Oh and one more thing... simply loading the php page in the browser works. ;-)

  • No browser errors either (IE, Firefox, etc)

  • Here are the links... may be helpful:

    PHP:

    walkmans-games.com/z/test2.php

    CONSTRUCT

    walkmans-games.com/z/index.html

  • FIXED IT!!!

    Upon further review I found that I had to place the following into my php file....

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

    Sorry... I'm used to working with flash. A lot of this is new for me.

    Thanks! :D

  • I'm attempting the same thing. I have WAMPSERVER/localhost setup with a PHP file on it. I want to be able to access that file with AJAX in preview mode.

    I added "header('Access-Control-Allow-Origin: *');" to the index.php file on my localhost and I'm still unable to make it work. If I export the project and put it on my local server it works, but I don't want to have to do that every time I want to test the game.

    Any ideas on why this might not be working for me? Are there any browser settings I have to change, etc?

    Edit: This is the browser error I'm getting:

    XMLHttpRequest cannot load localhost/dialog_test/dialog.php. Origin localhost is not allowed by Access-Control-Allow-Origin.

    Edit 2: Figured it out. I had to add "header('Access-Control-Allow-Origin: *');" to the PHP file I wanted to access. It's working now.

  • I'm trying to access a php file but can't get to work.. this is the php file:

    <?php

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

    ?>

    Now I really don't know what to do.. how do I request some information from the php?

    Can any1 make any example please?

    I just want to AJAX to retrieve some text information from a file in another domain.

  • any1?

    edit: It's working now!

    Had to put the file at a webserver instead of dropbox.

  • FIXED IT!!!

    Upon further review I found that I had to place the following into my php file....

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

    Sorry... I'm used to working with flash. A lot of this is new for me.

    Thanks! :D

    I'm sorry, I don't know how to delete this quote... I want just to thank You, agout1014, bye!

  • Uhmmmmm..., I'm new on creator2, I'm working with it from few hours, but the ONLY problem I've found (on a simple game-mysql test) WAS this.

    Thanks

  • I am having a problem to make a restful request with ajax plugin. I already added set header Access Control Allow Origin to * but the browser console kepps saying that the header is not present, would anyone know why?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • FIXED IT!!!

    Upon further review I found that I had to place the following into my php file....

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

    Sorry... I'm used to working with flash. A lot of this is new for me.

    Thanks!

    I had the same problem and this header declaration worked for me too. Thanks for sharing!

  • I have the same problem, I added header('Access-Control-Allow-Origin: *'); to my PHP file but it doesn't work

    My event sheet looks like this similar to agouti1014 but without the error message.

    From what I can see, it doesn't do the event On complete.

    Please help

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