How do I pull variables from a php page?

0 favourites
From the Asset Store
Template for making an interactive book or a simple story book
  • Can we start a forum just for AJAX? I think it would be very useful.

  • i have an issue that it wont grab the data even the example project wont work 0_0 i think the update has maybe broken the ajax functionality but not sure, i could just be being a n00b

  • alexh: do you have an example capx we can see?

  • I'm still working with it as much as I can. I'm working a full time job and also designing a website. I can send data to a php page and save it to a database but still working on retrieving the information and using it in the game.

  • Ok, I have it figured out mostly. I will post it in a few minutes. It's really simple for the most part. I used the example on here to do it, but it's just to show you how it is done.

  • Ok, here is the link:

    http://www.4shared.com/file/4djW66uI/construct_2_ajax_sample.html

    jax.php:

    <?php

    $level=77l

    echo $level

    ?>.

    I'm running my own server on my personal computer so I don't know exactly how this will work for you. If you have any questions I will try and help out as much as possible.

  • I am wondering if this was useful or not? If it wasn't please let me know so I can post something better. This was something I did really fast. I was/am hoping it will help anyone with the AJAX feature who is having troubles with it. Give me your opinions. And constructive criticism is very much welcome. Thanx

  • Maybe I'm a bit slow, but I still can't figure this out. Let's say, for instance, that our game has four different levels (layouts). We want a way for the person playing who has gotten to level 3 to be able to go to 7-11 or hang out with friends and not have to come back and start over at level (layout) 1 but continue where they left off at level (layout) 3.

    So how, utilizing these AJAX requests, php and subsequent sql, do we save which layout they were on and other pertinent info?

    I know we would need a way to create a php login, send the user's info to a php login script, update the sql database and maintain a session.

    We would also need to save the last layout (level) into the sql database for that user via a php script, then call that data into our html5 application from the database through php and into our game then have our game render the proper level (layout).

    So my question is, how would that be done?

  • By the way. Am I supposed to get a syntax error on line2?

    The syntax looks fine to me. I'm not seeing any unexpected ' or " or[] anywhere.

  • It's easy. When you send the call to the page just do this:

    "jax.php?level=" & level & "&score=" & score

    On your php page just call them like:

    <?php

    $level = $_GET['level'].

    $score = $_GET['score'].

    ?>

    I replaced the semicolons with periods because they won't show when I post this. And make sure there is a semicolon at the end of line 2 and 3. Then from there you can save to your database and call it back say when a user is logged in or something. If you can't figure it out I will repost a working demo when I get off work.

  • Thank you guys, this is all very useful information for me. I'm not a programmer, not in any professional sense, all my experience in the past has been scripting mods built with construction programs for other games (Elder Scrolls stuff). I've been reading a book about databases and php, and I was very excited when I saw the ajax ability in C2. However I also needed info on how to connect the dots between C2 and accessing a server database, so all this is very helpful for noobs like me. This topic has been bookmarked on my browser for reference.

  • than good! I will wait with keen that work. I am following this article. did not have privileges to write. From already thank you very much

  • Ok, I'm working on this example, but I ran into a minor problem. It seems to me that you can only pull one variable at a time from a request. So far I have multiple events for each request. I'm trying to figure out how I can do this without so many events. But I can use the same server side page to call all the data. I will post what I have when it's done.

  • OK, this is the website I'm working on:

    My Website

    Right now I have the AJAX example I'm working on posted on it. It's calling jax.php and sending the request to get two different values from the same page. In a little bit I will post the source for contruct 2.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Concatenation is the key on PHP side.

    String expressions on C2's side.

    Edit: Your website returns an error 503 atm.

    Edit2: No more.

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