AJAX and PHP: Sending information

Get help using Construct 2

Post » Thu Apr 19, 2012 1:29 am

No problem. I'm ashame of my ignorance, hahaha.

Here, I've read some threads before, and I have some question about this:

"post.php?name=" & Vname & "&score=" & Vscore

Vname is my variable and "name" is my field in PHP, right? Same thing to score.

Then if I write this on construct using the AJAX, it will post my Variables called "vName" and "vScore"?
B
6
Posts: 56
Reputation: 712

Post » Thu Apr 19, 2012 1:35 am

Yeah, that's more or less it.

Queries are separated as name=value pairs (like variables), with the pairs themselves separated by ampersands, so with "post.php?name=vname&score=vscore" The variable names would be 'name' and 'score' and their values would be 'vname' and 'vscore', respectively.

In php, this would be recieved in the $_GET array as

$_GET['name'] = vname
$_GET['score'] = vscore

B
10
S
5
G
1
Posts: 37
Reputation: 1,631

Post » Thu Apr 19, 2012 1:40 am

Best explanation that I've found so far. Thanks a lot!! Really.
B
6
Posts: 56
Reputation: 712

Post » Tue Apr 24, 2012 5:59 pm

Well, I worked a bit on it. Got some help with some students here in my University.

This is what I got:

<?php

$username = $_GET['name'];
$score = $_GET['score'];
$acerto = $_GET['Hit'];
$tempoReacao = $_GET['reactionTime'];

if (!isset($username) || $username == "") {
    echo "failure";
    exit;
}

if (!isset($score) || !is_numeric($score)) {
    echo "failure";
    exit;
}

if(!isset($acerto) || !is_numeric($acerto)){
echo "failure";
    exit;
}

if(!isset($tempoReacao)){
echo "failure";
    exit;
}

$entry = $username . "," . $score .";".$acerto.";".$tempoReacao."\n";


if (!file_put_contents("scores.csv", $entry, FILE_APPEND)) {
    echo "failure";
    exit;
}

echo "success";

?>

But I have a question now, a very important hone.

How do I use it with AJAX?

Like, I think that I must go this way:

Keyboard -> On Spacebar Pressed -> Ajax -> Request (request what and how?)

Thanks!
B
6
Posts: 56
Reputation: 712

Post » Wed Apr 25, 2012 10:04 pm

A little bump again :) (Hope it's not agains the forum's rules)
B
6
Posts: 56
Reputation: 712

Post » Wed Apr 25, 2012 10:44 pm

Search the website:

AJAX - Manual

AJAX - Tutorial
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Previous

Return to How do I....?

Who is online

Users browsing this forum: chcteacher, Televangelist and 26 guests