Ajax variables and user id

Get help using Construct 2

Post » Mon Mar 26, 2012 1:42 pm

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:
http://mysite.fr/ajax.php?username=username&game_id=game_id..

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
B
3
Posts: 8
Reputation: 316

Post » Mon Mar 26, 2012 2:06 pm

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.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Mon Mar 26, 2012 9:18 pm

The tutorial ajax example shows how you can do exactly that.Joe72012-03-26 21:21:04
B
14
S
6
G
5
Posts: 173
Reputation: 4,742


Return to How do I....?

Who is online

Users browsing this forum: BipolarMike, totoe and 17 guests