PROBLEMS TRYING TO POST VIA AJAX OBJECT

  • 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;

    dropbox.com/s/6h11h5zpa7os2tx/AjaxPostTest.capx

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

    BY THE WAY HERE IS THE URL TO CKECK IT OUT:

    cubacafelv.com/ajaxtest/index.html

  • 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.

  • 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:

    cubacafelv.com/ajaxtest/index.html

    dropbox.com/s/6h11h5zpa7os2tx/AjaxPostTest.capx

  • 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:

    cubacafelv.com/ajaxtest/getresults.php

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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...

  • Yes, then you need to update the PHP file >_>

  • 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?

  • 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.

  • lennaert:

    I KNEW IT WAS NOT GOING TO BE "A PIECE OF CAKE" THANX ANYWAY MY FRIEND FOR YOUR TIME... I'LL START LEARNING PHP RIGHT AWAY...

    BY THE WAY I SAW YOUR TUTORIAL AND YOUR PAGE AND PLAYED WITH ALL YOUR GAMES... MAN... YOU ARE GOOD!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)