Run AJAX in preview mode

0 favourites
  • 13 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi,

    From AJAX Tutorials I know that ajax can not run successfully in preview(run layout) mode.

    Maybe C2 Editor can add a resource folder in Projects window to import files like import sound/music. And put these files to the same folder with index.html in preview(run layout).

  • same question for me. How to run Ajax in preview mode?

  • At present I don't think it can. The easiest way to preview your work is to download and install XAMPP onto your computer. Then just put all the application files and php files you need into the htdocs folder of the xampp directory. Then open your browser and go to localhost and select the folder your application is in. Viola! Should work like a charm and function way better than the C2 preview.

    XAMPP

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I guess, the preview is to create a temporarily folder, put index.html and all related javascript files into.

    Because the target file of ajax's request is not in this folder, the request failed.

    If put the target file into the same folder, the execution environment may be the same as exporting.

  • it is temp and it will not work.

  • I use WAMP. It's free and it comes with a Windows installer. That's what used for that tutorial. For OSX, I use XAMPP mentioned earlier.

  • You need to send the header:

    Access-Control-Allow-Origin: *

    in the response from the server you send the AJAX request to. Otherwise, the browser will block the request.

  • The steps are list below:

    1. create a capx.

    +System: Start of layout
    [ul]
    	[li]Ajax request "readme.txt" (tag "read")[/li]
    [/ul]+ Ajax: on "read" complete
    [ul]
    	[li]Set text to AJAX.LastData

    2. use run layout.

    of course, the ajax will not be completed.

    3. search "preview.html" from my c:for example, I got the "preview.html" in path

    "C:/Users/Hau/AppData/Local/Temp/c2-12HER2/html5/preview.html"

    4. open this folder. There are many js files like AJAX_plugin.js, Text_plugin... etc.

    5. put "readme.txt" into this folder.

    6. open "preview.html"(in this folder) on browser.

    Now, the "readme.txt" file is in the same folder within "preview.html". And the Ajax is completed.

    Since this folder is created by C2 editor, and editor copy all necessary js files into it.

    Maybe editor can put "readme.txt" into this folder. So that "readme.txt" can be found in this case.

  • Hi, I maybe stupid... but I've installed Xampp

    When I connect to localhost, I have the Xampp page, where I can check the status etc...

    What do I do from there to launch the game ?

    I've copied the files from the export to a directory in htdocs.

    But if I type the Url   localhost/xampp/htdocs/game/index.html

    It doesn't work..

    nothing is found.

    Is there another way or am i doing something wrong ??

    Thx

  • Its probably localhost/game/index.html

  • Yes...

    Thanks !

    But... my Ajax access to an Sql database online doesn't work.

    Is it normal ? or Should that work too ?

  • I don't think AJAX can directly access a SQL database.

    AJAX is a call to a script which handles said access.

  • AJAX was really designed for people who are already familiar with server side scripting and databases. If you don't know about that already, using the AJAX object is likely to be a very steep learning curve.

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