0 favourites
  • 7 posts
  • Hello everyone!

    I would like help on the system "AJAX" that can send and retrieve data.

    For the moment I can send the data with an Ajax request and store it on my server with PHP.

    Then I would like to know how to retrieve data using "AJAX.LastData".

    With my echo 'success'I should get 'success' in my text.

    And when I test my AJAX.LastData isempty

    Thanks for your answers. :)

    formulaire.php :



    $message = $_GET['mes'];

    $sql=$pdo->exec('INSERT INTO informations SET message_informations="'.$message.'" ');


    test.php :


    echo "success |";

    ?> <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Hi there!

    I made a simple send to database, and receive from database example.

    Please make sure you host this on your web server, im using WAMP server, and localhost. I got instructions inside the example how to set up your new database and database table.

    Here is the link dropbox for the .capx project, and two php files, one sends the info to database, and one receives.


    Just export the .capx project to HTML 5 and copy the files to your web server.

    If you have any questions, please let me know!

    <img src="smileys/smiley1.gif" border="0" align="middle">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you don't set up cross-origin resource sharing (CORS), all AJAX requests will fail in preview mode. See the AJAX object's manual entry for more information.

  • Can get around it by using this inside your php code

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

    but it was not needed for any of my projects.

  • Hello everyone and thank you for your help.

    Ashley I see what you mean, but I do not know where I have to setup cross-origin. It's in my construct2 project or in my PHP file?

    GameThirsty I'll try your file. But in the meantime I do not see the difference between my file and yours. My capx work like yours. I flawlessly records in the database, but it does not recover AJAX.LastData on my other file as the value of this file there is just <echo "foo"?>

    I do not understand why it does not work.

    Thank you again.

  • Like Ashley said, in order to bypass origin, you can do something like

    (inside all php files)


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



  • Thanks !!

    It's ok now. Thank you for yours answers :)

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