AJAX.Lastdata Problem

Get help using Construct 2

Post » Thu Mar 15, 2012 10:16 pm

Hello -

I am still very new to construct2.

I have a very simple php file on my server that does the following:
<?php
echo "it works";
?>

Now for construct2 I have a single layout with a text object called "Text" that has a default text of "waiting".

My event sheet is:
-System->On start of layout-> AJAX.Request "http://mysite.com/test.php"
-AJAX->On Complete->Text->Set text to ->AJAX.Lastdata
-AJAX->On Error->Text->Set text to ->"Error"

No matter what I am getting an error.

Please note that I have had 100% success with adding data to mysql through php that originates in construct2... the problem I am getting is receiving data back from php on my server (with or without placing the files on my server).

Any ideas?

Thanks.
B
10
S
3
G
3
Posts: 29
Reputation: 2,769

Post » Thu Mar 15, 2012 10:33 pm

Have you seen the section in the manual about cross-domain or preview AJAX requests? Is that relevant?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Mar 15, 2012 10:43 pm

Yes... I am running my files on my own server so there should not be an issue there... please note though that I have been able to historically make this work, but I recently upgraded to construct version r81.

A bug maybe? Sending data to php is still not a problem... my php will even update mysql tables with no issue.

Its just trying to load player data from php. I decided to drop the complexities of tokenat, etc and attempt to just make a simple project that will simply indicate that the receiving of data works. Not working, but I hope I am not missing anything... that would be embarrassing. LOL
B
10
S
3
G
3
Posts: 29
Reputation: 2,769

Post » Thu Mar 15, 2012 10:44 pm

Oh and one more thing... simply loading the php page in the browser works. ;-)
B
10
S
3
G
3
Posts: 29
Reputation: 2,769

Post » Thu Mar 15, 2012 10:47 pm

No browser errors either (IE, Firefox, etc)
B
10
S
3
G
3
Posts: 29
Reputation: 2,769

Post » Thu Mar 15, 2012 10:59 pm

Here are the links... may be helpful:

PHP:
http://www.walkmans-games.com/z/test2.php

CONSTRUCT
http://www.walkmans-games.com/z/index.html
B
10
S
3
G
3
Posts: 29
Reputation: 2,769

Post » Fri Mar 16, 2012 6:40 am

FIXED IT!!!

Upon further review I found that I had to place the following into my php file....
"header('Access-Control-Allow-Origin: *');"

Sorry... I'm used to working with flash. A lot of this is new for me.

Thanks! :D
B
10
S
3
G
3
Posts: 29
Reputation: 2,769

Post » Wed Apr 04, 2012 3:05 am

I'm attempting the same thing. I have WAMPSERVER/localhost setup with a PHP file on it. I want to be able to access that file with AJAX in preview mode.

I added "header('Access-Control-Allow-Origin: *');" to the index.php file on my localhost and I'm still unable to make it work. If I export the project and put it on my local server it works, but I don't want to have to do that every time I want to test the game.

Any ideas on why this might not be working for me? Are there any browser settings I have to change, etc?

Edit: This is the browser error I'm getting:
XMLHttpRequest cannot load http://localhost/dialog_test/dialog.php. Origin http://localhost:50000 is not allowed by Access-Control-Allow-Origin.

Edit 2: Figured it out. I had to add "header('Access-Control-Allow-Origin: *');" to the PHP file I wanted to access. It's working now.robit_studios2012-04-04 03:24:05
B
20
S
5
G
3
Posts: 65
Reputation: 3,764

Post » Wed Jul 25, 2012 5:39 am

I'm trying to access a php file but can't get to work.. this is the php file:
<?php
header('Access-Control-Allow-Origin: *');
?>

Now I really don't know what to do.. how do I request some information from the php?
Can any1 make any example please?
I just want to AJAX to retrieve some text information from a file in another domain. Guif0DA2012-07-25 06:09:30
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Post » Thu Jul 26, 2012 12:37 am

any1?

edit: It's working now!
Had to put the file at a webserver instead of dropbox.Guif0DA2012-07-26 01:55:07
B
30
S
6
G
5
Posts: 433
Reputation: 6,061

Next

Return to How do I....?

Who is online

Users browsing this forum: jobel, Timedoor Indones and 22 guests