I'm missing something with the AJAX object

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • From what I can tell, if I load an AJAX object, I can then use that data as a string, from AJAX.LastData. If it's in the correct JSON format, I can then load that string as a table array?

    Is this correct?

    I'm running a local server on localhost:82 (LAMP stack)

    This is what I have now:

    on start of layout -> load localhost:82/phpfile.php with tag "sometag"

    on "sometag" completed -> load array vocab from ajax.LastData

                          -> set variable numberOfColumns from vocab.width

    Here is the format of my JSON file - It does pass as valid JSON:

    {"c2array":true,"size":[7,4,1],"data":[[["I"],["w?"],["?"]],[["you"],["n�"],["?"]],[["him"],["t?"],["?"]],[["her"],["t?"],["?"]],[["it"],["t?"],["?"]],[["they"],["t?men"],["??"]]]}

    Here is the .capx: http://dl.dropbox.com/u/12722403/flashCard.0.4.capx

  • The preview server runs on localhost:50000, which counts as a different origin to localhost:82, so the browser will block the request due to the same-origin policy. See the section on cross-domain requests in the AJAX documentation.

    Also, setting up a separate PHP server to serve a simple JSON file is unnecessary. You can do it by using project files.

  • The PHP file is part of a much bigger project - it pulls data from a database. The real URL is 2 folders deep.

    This problem happens when I've uploaded the project to a folder on localhost:82. I've also tried it without the leading localhost (only using /folder1/folder2/phpfile.php) I'll play around with project files, but I'd rather use files in my existing folder structure.

  • OK...I've gotten it to work, but I can't figure out WHY. If I put a browser ALERT after the AJAX JSON load, all is well. If I take it out, the quiz skips to the end, and the grading button is shown. The capx file is at http://dl.dropbox.com/u/12722403/flashCard.0.5.JSON.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The problem was with my timer - I didn't have the proper check to make sure it didn't start until after the JSON was loaded.

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