How do I Use Ajax and PHP?

Get help using Construct 2

Post » Fri May 13, 2016 7:35 am

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.
ImageImage
B
49
S
15
G
2
Posts: 268
Reputation: 6,617

Post » Fri May 13, 2016 11:03 am

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.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Sat May 14, 2016 6:19 am

lennaert wrote: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?
ImageImage
B
49
S
15
G
2
Posts: 268
Reputation: 6,617

Post » Sun May 15, 2016 5:03 am

KTML5 wrote:
lennaert wrote: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 ?
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue May 17, 2016 8:06 am

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.
ImageImage
B
49
S
15
G
2
Posts: 268
Reputation: 6,617

Post » Tue May 17, 2016 9:15 am

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)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Thu May 19, 2016 8:32 am

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.
ImageImage
B
49
S
15
G
2
Posts: 268
Reputation: 6,617

Post » Thu May 19, 2016 9:13 am

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.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572


Return to How do I....?

Who is online

Users browsing this forum: dand, mickclarke, Yahoo [Bot] and 27 guests