AJAX.LastData

Get help using Construct 2

Post » Sun Nov 17, 2013 6:11 pm

Hello everyone!

I would like help on the system "AJAX" that can send and retrieve data.
For the moment I can send the data with an Ajax request and store it on my server with PHP.
Then I would like to know how to retrieve data using "AJAX.LastData".
With my echo 'success'I should get 'success' in my text.
And when I test my AJAX.LastData isempty


Thanks for your answers. :)


formulaire.php :

<?php
require_once('cn.php');

$message = $_GET['mes'];
$sql=$pdo->exec('INSERT INTO informations SET message_informations="'.$message.'" ');

?>

test.php :

<?php
echo "success |";
?>
B
3
Posts: 13
Reputation: 351

Post » Sun Nov 17, 2013 9:53 pm

Hi there!

I made a simple send to database, and receive from database example.

Please make sure you host this on your web server, im using WAMP server, and localhost. I got instructions inside the example how to set up your new database and database table.

Here is the link dropbox for the .capx project, and two php files, one sends the info to database, and one receives.

https://www.dropbox.com/sh/rxzsl17f48gk6g1/4k2IccWhQb

Just export the .capx project to HTML 5 and copy the files to your web server.

If you have any questions, please let me know!
GameThirsty2013-11-17 21:55:46
B
18
S
6
Posts: 348
Reputation: 2,633

Post » Sun Nov 17, 2013 10:02 pm

If you don't set up cross-origin resource sharing (CORS), all AJAX requests will fail in preview mode. See the AJAX object's manual entry for more information.
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Sun Nov 17, 2013 10:03 pm

Can get around it by using this inside your php code

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

but it was not needed for any of my projects.
B
18
S
6
Posts: 348
Reputation: 2,633

Post » Mon Nov 18, 2013 10:58 am

Hello everyone and thank you for your help.

Ashley I see what you mean, but I do not know where I have to setup cross-origin. It's in my construct2 project or in my PHP file?

GameThirsty I'll try your file. But in the meantime I do not see the difference between my file and yours. My capx work like yours. I flawlessly records in the database, but it does not recover AJAX.LastData on my other file as the value of this file there is just <echo "foo"?>

I do not understand why it does not work.
Thank you again.
B
3
Posts: 13
Reputation: 351

Post » Mon Nov 18, 2013 7:09 pm

Like Ashley said, in order to bypass origin, you can do something like

(inside all php files)

<?php

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

PHP CODE HERE

?>GameThirsty2013-11-18 19:10:59
B
18
S
6
Posts: 348
Reputation: 2,633

Post » Wed Nov 20, 2013 4:43 pm

Thanks !!
It's ok now. Thank you for yours answers :)
B
3
Posts: 13
Reputation: 351


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 34 guests