How do I Use Ajax and PHP?

0 favourites
  • 8 posts
From the Asset Store
Paypal PHP Supports multiple platforms, Web/html5 Android, IOS. (Including storing transaction data)
  • Sounds like a pretty dumb question, but I'm not really following what's going wrong with it.

    I have a PHP file that runs some code and than echoes a number, but the result I get is the entire PHP file, rather than the echoed result. It doesn't seem like I'm doing anything wrong.

  • Likely your Ajax request is not getting served a PHP interpreted reply but a straight up text file containing the PHP script.

    Make sure your PHP file is on a PHP capable webserver and that you are actually addressing it by means of the webserver address and not by means of a local file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Likely your Ajax request is not getting served a PHP interpreted reply but a straight up text file containing the PHP script.

    Make sure your PHP file is on a PHP capable webserver and that you are actually addressing it by means of the webserver address and not by means of a local file.

    I kinda figured that since it auto created HTML tags it was running the PHP correctly, but because of my results, I believe your right. I'm curious, if I'm running in test mode in Construct 2 and POST the file with AJAX, should it work? Local servers should just normally be PHP compatible, right?

  • > Likely your Ajax request is not getting served a PHP interpreted reply but a straight up text file containing the PHP script.

    >

    > Make sure your PHP file is on a PHP capable webserver and that you are actually addressing it by means of the webserver address and not by means of a local file.

    >

    I kinda figured that since it auto created HTML tags it was running the PHP correctly, but because of my results, I believe your right. I'm curious, if I'm running in test mode in Construct 2 and POST the file with AJAX, should it work? Local servers should just normally be PHP compatible, right?

    What do you mean with "post the file" ?

    Are you sending the PHP script to the server for it to be processed as a PHP script ?

  • Yeah. As far I can tell, anyways.

    I have a PHP file in my Project Files, and I'm using the Post to URL action of AJAX.

    I honestly think my problem is that I'm putting my PHP's address in the URL parameter.

    If that is the problem, is there any tutorials or something that explains that stuff? I've been trying to find one on my own but haven't found one.

  • The php file should reside on your webserver, not within your project. (Unless it's a html5 project on a webserver)

    The url your calling should be the Web address of the php file on your webserver .

    Try and read up on info how php files are served up.

    Google how WAMP works. (Windows apache mysql php)

  • Okay haha I figured it was something like that. Thanks lennaert! Also, it's probably not normally possible to run PHP with Node Webkit without some sort of modification to Node Webkit itself, is there?

    I guess since this isn't working for me I'll just use Node Webkit. My plan was to use PHP for file system management, under the impression that it was as universal as Javascript. I had no clue how to use PHP, I go and learn a bit of it, and now it was a waste of time XD.

    Still, thanks for the help on this subject! I'll definitely be needing to know these things when I set up my own game server.

  • Hi,

    Indeed, for PHP to work you need an interpreter (PHP). It is a separate program.

    The syntax actually resembles javascript quite a bit, but it requires its own engine to run.

    It does have some greater advantages over Javascript when you want to do file manipulation.

    PHP is often used as a back-end system for databases and information management systems.

    Good luck, and if you have any questions regarding PHP feel free to ask.

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