CocoonJS and AJAX frustration

Discussion and feedback on Construct 2

Post » Mon Aug 18, 2014 3:17 am

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...
Twitter: https://twitter.com/pudgyplatypus

Learn to make a clicker game for cheap!
https://www.scirra.com/store/games-with ... e-game-666

Try out Pixel Golf on the Scirra Arcade!
https://www.scirra.com/arcade/sports-ga ... el-golf-67

Pudgy Platypus Games website!
www.pudgyplatypus.com
B
59
S
20
G
5
Posts: 212
Reputation: 7,390

Post » Mon Aug 18, 2014 4:28 am

If it doesn't work with cross domain settings, you should try with JSON-P
B
97
S
35
G
29
Posts: 3,139
Reputation: 28,371

Post » Mon Aug 18, 2014 2:02 pm

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?
Twitter: https://twitter.com/pudgyplatypus

Learn to make a clicker game for cheap!
https://www.scirra.com/store/games-with ... e-game-666

Try out Pixel Golf on the Scirra Arcade!
https://www.scirra.com/arcade/sports-ga ... el-golf-67

Pudgy Platypus Games website!
www.pudgyplatypus.com
B
59
S
20
G
5
Posts: 212
Reputation: 7,390

Post » Mon Aug 18, 2014 3:29 pm

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?
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Mon Aug 18, 2014 7:58 pm

@Djfuzion 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:

Code: Select all
<?php

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');

echo 'Got it!';

?>



If it doesn't work, depending on your server, let's try another solution:

Code: Select all
<?php
header('Content-type: application/json');
$url=$_GET['url'];
$json=file_get_contents("http://www.yourdomain.com/text.txt");
echo $json;
?>




It's basic JSON-P, it worked everything if we couldn't get cross-domain.
B
97
S
35
G
29
Posts: 3,139
Reputation: 28,371


Return to Construct 2 General

Who is online

Users browsing this forum: Sockratease and 5 guests