PROBLEMS TRYING TO POST VIA AJAX OBJECT

Get help using Construct 2

Post » Thu Feb 13, 2014 9:29 am

I HAVE BEEN TRYING TO UNDERSTAND HOW TO POST VIA AJAX OBJECT TO REPLACE A SIMPLE PHP FILE VALUE... MY getresults.php FILE WITH JUST A SINGLE NUMBER (400) (https://www.dropbox.com/s/1sbduepd7xf3vqh/getresults.php) IS EASY TO BE REQUESTED WITH AJAX TO MY Results Variable, AND WITH A BUTTON CLICKED ACTION ADD 100 TO Results Variable UPGRADING THE VALUE TO(500)... BUT I CAN'T FIND THE WAY TO POST BACK THE NEW SIMPLE VALUE OF(500) JUST TO REPLACE THE OLD ONE IN MY getresults.php FILE... CAN SOME MASTER GENIUS OUT THERE GIVE A HAND TO THIS BRAINLESS NEWBIE GUY?

THIS IS THE CAPX FILE;
https://www.dropbox.com/s/6h11h5zpa7os2tx/AjaxPostTest.capx

THANX IN ADVANCE.............

BY THE WAY HERE IS THE URL TO CKECK IT OUT:
http://cubacafelv.com/ajaxtest/index.htmlvillmaxie2014-02-13 09:49:56
B
21
S
12
G
9
Posts: 24
Reputation: 7,570

Post » Thu Feb 13, 2014 9:55 am

You need to replace the backslashes for forward slashes in the URLS

In the second post you need to place your double qoute propper:
"http://cubacafelv.com/ajaxtest/getresults.php?action=&Results"
change to
"http://cubacafelv.com/ajaxtest/getresults.php?action="&Results


And very ikely, you need to place:

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

At the top of you PHP file right below <?php
This will make it work from PReview mode.
If you do not add it, it will only work once you exported and uploaded to that cub site of yours.lennaert2014-02-13 09:57:21
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Thu Feb 13, 2014 12:23 pm

lennaert:

I tried changing the slashes forward in the URLS and in the second post a change the double quotes:
"http://cubacafelv.com/ajaxtest/getresults.php?action="&Results

But I still getting the 400 initial value when I refresh (restart) the page... I actualized the page and the capx file with your suggestions so you can check it out:

http://cubacafelv.com/ajaxtest/index.html

https://www.dropbox.com/s/6h11h5zpa7os2tx/AjaxPostTest.capx
B
21
S
12
G
9
Posts: 24
Reputation: 7,570

Post » Thu Feb 13, 2014 12:53 pm

That 400 is because you request the page through ajax at the start of layout and places it in your text.

The page shows the 400.

Just visit your test page directly:

http://cubacafelv.com/ajaxtest/getresults.php

Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Thu Feb 13, 2014 8:14 pm

lennaert:

I TRIED STARTING THE PAGE ADDED THE 100 TO GET 500 AND WITHOUT STARTING OR REFRESHING THE PAGE I CLOSE THE APP AND CHECK THE PHP DIRECTLY BUT STILL SHOWING THE 400...IT NEVER UPGRADE THE VALUE...
ANY OTHER SUGGESTION YOU MAY HAVE? villmaxie2014-02-13 20:15:24
B
21
S
12
G
9
Posts: 24
Reputation: 7,570

Post » Thu Feb 13, 2014 8:22 pm

You send a get request with the value to the php page, and afterwards the page still shows 400.

Thats in the PHP page you are adressing in your ajax get url.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Fri Feb 14, 2014 6:39 am

lennaert:

IN FACT WHAT I WANT TO DO IS UPGRADE(REWRITE,REPLACE) THE PHP FILE WITH THE NEW VALUE (500) VIA THE POST AJAX OBJECT.

LETS SAY THAT THE GAME IS A SLOT MACHINE, WHEN YOU START PLAYING YOU HAVE 400 POINTS THAT YOU EARNED THE LAST DAY, THEN YOU PLAY AND EARN 100 MORE POINTS... TOMORROW WHEN YOU START PLAYING YOU SHOULD HAVE 500 POINTS...

MAYBE WITH THIS EXAMPLE YOU CAN HAVE A BETTER POINT OF VIEW TO HELP ME...
B
21
S
12
G
9
Posts: 24
Reputation: 7,570

Post » Fri Feb 14, 2014 6:42 am

Yes, then you need to update the PHP file >_>
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Fri Feb 14, 2014 7:07 am

lennaert:

THAT'S WHAT I HAVE BEEN TRYING TO DO POSTING WITH AJAX... IS THERE ANOTHER WAY (NOT MANUALLY) TO UPDATE THE PHP FILE WITHIN C2?villmaxie2014-02-14 07:16:14
B
21
S
12
G
9
Posts: 24
Reputation: 7,570

Post » Fri Feb 14, 2014 7:41 am

You cant do it with a simple ajax call   hehe

You will need to update the PHP file itself ..


For example, write some PHP code to catch that value you are sending and set it in a database or write it to some file.
lennaert2014-02-14 07:42:31
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Next

Return to How do I....?

Who is online

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