1

Mates, I'm developing a facebook app. It turns out that when I run it via my server's url, it works fine. But, when I run it on facebook, if I check the network requests, the request that tries to save info is somehow cancelled.

This is my server's URL: http://www.conamor.org/apps/aventuracenter/pacman/public/index.php/game

This is from facebook: https://apps.facebook.com/avcpacman/

As you can see (If you run it), it makes a post request in order to save player's score. But for some reason I can't understand, when i run it on facebook, this request's status is Cancelled.

Any ideas? Thanks in advance!

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
Pablo
  • 1,173
  • 4
  • 18
  • 46
  • Have you enabled cross-domain calls on your server? The default is that any ajax must be to the hosting server, unless cross domain is enable for the ajax call AND on the remote server. – iCollect.it Ltd Sep 19 '13 at 11:19
  • And how can I enable cross-domain calls? – Pablo Sep 22 '13 at 16:20

2 Answers2

1

You need to enable CORS on your own server by putting Access-Control-Allow-Origin: facebook.com in your response headers. In addition, since Facebook is https secured and your website isn't, you likely need to enable mixed content in your browser as well to make it work. Long term you might want to enable https security for your website as well.

More info on cors: http://www.html5rocks.com/en/tutorials/cors/.

More info on mixed content: https://developer.mozilla.org/en-US/docs/Security/MixedContent

Nzall
  • 3,439
  • 5
  • 29
  • 59
0

To enable to CORS (Cross-origin resource sharing) Add:

<?php
    header('Access-Control-Allow-Origin: *');
  the reset of your saving code
?>

& Since you are using AJAX you have to ues JSON as dataType:

$.ajax({ 
        type: "POST",
        url: "http://TO_REMOTE_SERVER/dummy.php",
        data: data,
        datatype: 'json'
    });
Adam Azad
  • 11,171
  • 5
  • 29
  • 70