CocoonJS and AJAX frustration

0 favourites
  • 5 posts
From the Asset Store
MM_Preloader
$19.99 USD
Various preloading features. Preload textures of entire layout, custom preloading, etc.
  • Please please please tell me someone has gotten a CocoonJS game compiled through their website that can actually use AJAX to get data from a server?

    This has become quite frustrating, especially since the AJAX commands work great when just using the CocoonJS app to play my game...

    And yes, I have the cross domain setting in my php file on the server, it works great until it actually gets compiled through CocoonJS...

  • If it doesn't work with cross domain settings, you should try with JSON-P

  • I'm not exactly sure what that means? I'm just using one of the basic functions of C2 that works perfectly fine with my php on a server through the browser, CocoonJS app launcher but refuses to work when it gets into their hands and they compile it.

    There is no way that all of the games compiled through CocoonJS do not use any AJAX in their apps, or am I just being too hopeful here?

  • I use AJAX in one of my current projects, and it works completely fine in a game compiled through CJS and deployed to Google Play. It's in beta currently, so not public, but I've tested it with 20+ users on multiple networks and devices and it's been solid.

    It's likely then that your issue is either in your events or server-side. What is the exact problem that you're having?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've tried to use AJAX via cocoonJS launcher and it worked because it depends on server side.

    CocoonJS doesn't have own domain, so it's not allowed to get resources from other servers.

    My php script should be:

    <?php
    
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type');
    
    echo 'Got it!';
    
    ?>[/code:pw5w5zwf]
    
    If it doesn't work, depending on your server, let's try another solution:
    
    [code:pw5w5zwf]<?php
    header('Content-type: application/json');
    $url=$_GET['url'];
    $json=file_get_contents("http://www.yourdomain.com/text.txt");
    echo $json;
    ?>
    
    [/code:pw5w5zwf]
    
    It's basic JSON-P, it worked everything if we couldn't get cross-domain.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)