Problem with Ajax + PHP

Discussion and feedback on Construct 2

Post » Thu Apr 19, 2012 8:27 pm

Hello Guys,
I'm having problems with PHP + Ajax.
The problem is that I am not knowing where to put my. Php
I made an example by putting the folder C: \ Program Files \ Apache Software Foundation \ Apache2.2 \ htdocs \ construct, but failed.
Can anyone help me?


IMAGE
http://www.imagebam.com/image/ffa2ae185798372


PHP
<?php
if ($_GET['mode']=="save") {
$score = $_GET['score'];
}
$fp = fopen("testFile.txt", "a");
$escreve = fwrite($fp, "Test MSG");
fclose($fp);
?>
B
3
Posts: 10
Reputation: 295

Post » Thu Apr 19, 2012 9:16 pm

This is kind of out of the scope of this forum, since Apache and PHP have abundant ressources all over the web to learn from.

I'd say you should have a "www" folder in your apache directory and this is where you should have a jax.php file containing your code.
This is how you'll be able to access "http://localhost/jax.php?whatever".

Check the How do I FAQ there are several examples treating about AJAX and PHP in the "AJAX" section, but for beginner documentation about having a local webserver and how to write correct PHP, you should make a search on google and learn from there.Kyatric2012-04-19 21:16:33
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 » Fri Apr 20, 2012 1:04 am

if you placed it in \ htdocs \ construct then you should request localhost/construct/jax.php instead of localhost/jax.php
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Fri Apr 20, 2012 11:46 am

@Fimbul, that's not quite right, Construct 2 runs its own preview server. So unless you run Apache on a different port (e.g. localhost:80) and specifically AJAX the URL "http://localhost:80/construct/jax/php", it won't work. Currently I think it is easiest to run a server on the open web, e.g. www.example.com/jax.php - then you don't have to change anything from preview to export, either.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Fri Apr 20, 2012 11:28 pm

Was actually wondering how to get files into the local server. Stumbled on this thread, sweet.
B
18
S
3
Posts: 12
Reputation: 1,617


Return to Construct 2 General

Who is online

Users browsing this forum: Artpunk and 11 guests