Ajax variables and user id

0 favourites
  • 3 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi

    I have several variables (username,game_id,...) in my PHP script

    I would like to send an Ajax request with those variables in construct:

    mysite.fr/ajax.php

    How can I pass my variables from my PHP to the js file ?

    I tried to generate my variables like that :

    <script>

        <?php echo 'username="'.$user->id.'";';?>

    </script>

    <script src="c2runtime.js"></script>            

    but it doesn't work ..

    any idea ?

    Fabien

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You're taking it the wrong way I think.

    AJAX sends a request from within the already running C2 app to an external script (php) and gets an answer in return. The script page you're trying to access shouldn't contain the c2runtime or anything.

    So basicly from inside C2 you execute an ajax request to "yoururl.php?yourvariables", the script in "yoururl.php" processes the variables and return an answer to the app.

    For the server side, it's PHP scripting.

    Check the items listed in the "AJAX" section of the how do I FAQ there are complete working examples of communication between the app and serverside PHP.

  • The tutorial ajax example shows how you can do exactly that.

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