AJAX Object

Discussion and feedback on Construct 2

Post » Fri Sep 05, 2014 12:47 am

Anyone know how to send POST / GET to a PHP file without using AJAX ?? I've given up using does not work because !!! Does not bring the return of PHP !!! Ja quit !!
Thank you.
B
5
Posts: 19
Reputation: 690

Post » Fri Sep 05, 2014 7:04 am

Hi

What is your problem with the return ?
AJAX is working fine for me, have been making a Login before, so can you specify your problem ? And show your code or Blocks in C2 ? ^^
B
7
S
1
Posts: 55
Reputation: 810

Post » Wed Sep 10, 2014 8:18 am

Hi.
I have the same problem, no response to show in Construct.

Here are my PhP and my Blocks :

Code: Select all
<?php
   $serveur = "127.0.0.1";
   $db ="oze";
   $user = "oze";
   $mdp = "oze";
   
   $login = $_GET['oze_login'];
   $passwd = md5($_GET['oze_passwd']);
   
   
   //Connexion DB
   $link = mysqli_connect($serveur, $user, $mdp, $db) or die("Erreur de connexion au serveur !" . mysqli_error($link));
   
   $qPseudoUnique = "SELECT Pseudo_Joueur, Mdp_Joueur FROM joueur WHERE Pseudo_Joueur = '$login';" or die("Erreur de requête !" . mysqli_error($link)); // Existence ou non d'un pseudo et tests de connexion
   if ($resPseudo = mysqli_query($link, $qPseudoUnique)) {
      if (mysqli_num_rows($resPseudo) != 0) { // Si la requête renvois un résultat
         while ($row = mysqli_fetch_array($resPseudo)) {
            $pseudoJoueur = $row["Pseudo_Joueur"]; // Attribution du pseudo et mot de passe à des variables
            $mdpJoueur = $row["Mdp_Joueur"];
         }
         if (($pseudoJoueur == $login) && ($mdpJoueur == $passwd)){ // Si login et Mdp valides, connexion
            echo "Connecté !";
         }else { // Sinon message d'erreur
            echo "Vérifiez votre mot de passe !";
         }
      }else { // Si pas de compter, inscription d'un nouveau joueur
         $qNouveau = "INSERT INTO `oze`.`joueur` (`ID_Joueur`, `Pseudo_Joueur`, `Mdp_Joueur`) VALUES (NULL, '$login', '$passwd');" or die("Erreur de requête !" . mysqli_error($link));
         if ($resultats = mysqli_query($link, $qNouveau)) {
            echo "Inscription réussie !";
         }else {
            echo "Erreur lors de l'inscription !";
         }
      }
   }
   echo "Boulet !";
   
   mysqli_close($link);
?>


Image

Thank you for your help.
B
8
S
1
G
1
Posts: 6
Reputation: 1,815

Post » Wed Sep 10, 2014 8:21 am

OK... Well.... I just find the answer...
We must add :

Code: Select all
header('Access-Control-Allow-Origin: *');


Juste after <?php in our PhP file !
It works fine for me.
B
8
S
1
G
1
Posts: 6
Reputation: 1,815

Post » Wed Sep 10, 2014 8:29 am

s3rg385 wrote:Hi.
I have the same problem, no response to show in Construct.

Here are my PhP and my Blocks :

[code][/code]

Image

Thank you for your help.


Have you tried for debugging
1. set tDebug1 to your request url to make sure tbPseudo.Text is correct and not empty
2. Entered the request url in to a browser and does it display anything?

Edit: Nevermind :)
B
32
S
7
G
2
Posts: 317
Reputation: 2,851

Post » Wed Sep 10, 2014 11:43 am

The most common reason it doesn't work is the cross-domain security restrictions in the browser. This is documented.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,600


Return to Construct 2 General

Who is online

Users browsing this forum: sunisa2532, taker7 and 21 guests