How do I read multiple time ajax.lastdata?

0 favourites
  • 6 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • It's been weeks now since I'm searching an anwser but I can't find any.

    I can post ajax and read ajax, but only once! Even if I reload firefox or chrome, I get the same output than the last time I read the "ajax.lastdata", so I need to delete my cookie , my history ect ect, and then I can post/request once again, but still only once.

    humain.tech/QQCH

    To write on MYFILE.txt I write on a php who redirect:

    <?php file_put_contents("MYFILE.txt", $_GET['DATA']); ?>

    But I dont really think it's usefull... it's not showing any errors.

    So when I request somthing, ajax.lastdata stay the same (until I delete my history,cookie,ect,ect) even if I change the data on my server myself.(even tho it's working with my write.php code)

  • Are you sure the problem is in Construct2, and not in your PHP script or server or browser etc.?

    Have you tried requesting the same file directly from the browser address line?

  • Are you sure the problem is in Construct2, and not in your PHP script or server or browser etc.?

    -I'm not sure of anything.. Do you think I can use another php code to retreve my .txt data? and if yes how?

    ~~~~

    Have you tried requesting the same file directly from the browser address line?

    -Yes I'v made a tchat in ajax, without C2 and it's working just fine.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Actually if I try to request from project, it's not working at all, there's an error (of course I cannot know what error it is because AJAX dont have a ajax.error)

  • Try opening browser console (F12), maybe you'll see the error message there.

  • DONE!

    Found out myself!

    just use a .php to post and a .php to get..

    I do it like this =

    I create 2 .php file, one "send.php" and one "get.php"

    inside send.php you write:

    <?php file_put_contents("data.txt", $_GET['data']);?>

    inside get.php you write:

    <?php file_get_contents("data.txt", $data)?>

    And ADD an empty file named data.txt

    So in total you just created 3 files that you will put in the same folder than your index.html file once exported.

    FINALLY

    In construct 2:

    to send:

    You add the action AJAX send to url:

    ~TAG "done-send"

    ~URL "./send.php?data=" & VAR

    (you put your own variable instead of VAR, like textbox.text for exemple)

    to get:

    You add the action AJAX request from url:

    ~TAG "done-get"

    ~URL "./get.php?data"

    Then you can add an event 'AJAX: on tag "quest-done" '

    Who trigger the action 'set textbox.text to ajax.lastdata'

    or even 'set variable to ajax.lastdata'

    Like this you'll be able send and get what's in the file "data.txt" of your website!

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