0

I have a HTML5 game working perfectly in desktop and for the leadersboards (and for more stuff) I use ajax to send parameters and receive data.

The fact is that everything is working fine but in cocoon, in cocoonjs is not working at all and I don´t know why, jQuery is supported and in theory everything should be fine. Does anyone know why is not working this code?

Thanks in advance.

$.ajax({
 type: 'GET',
 url: this.baseURL+'/getScores.php',
 data: { 
      'theGame': '1', 
      'theOrder': 'ASC'
 },
 fail: function(msg){
      alert(msg);
 }
 });

And I´m also trying this code (not working in cocoonjs)

$.getJSON( STK.root.urlBase+"/getScores.php",
 { theGame: "1", theOrder: "ASC" }
)
 .done(function(data) {
      //DO STUFF
 })
 .fail(function( jqxhr, textStatus, error ) {
     console.log( "Request failed: " + err );
 });
vanntile
  • 2,727
  • 4
  • 26
  • 48
Pizzaboy
  • 331
  • 2
  • 14
  • Your code looks all-right (both variants, except for the difference with the slash in the URL). What error do you see? – Tomalak May 25 '15 at 17:08
  • Tomalak, the code is ok (I edited that), it´s just simply that I was trying an absolut URL and I edited that incorrectly :) Both parts of code are working perfectly in desktop, the thing is in cocoonjs, the fail() callback is executing everytime... – Pizzaboy May 26 '15 at 07:21
  • With what error? Do a `console.log(arguments)` and inspect the result. – Tomalak May 26 '15 at 07:24
  • I´m getting just and "error" with this code: `.fail(function( jqxhr, textStatus, error ) { var err = textStatus + ", " + error; alert( "textStatus: " + textStatus ); alert( "error: " + error ); });` textStatus is "error" and error is nothing :) – Pizzaboy May 26 '15 at 07:53
  • Of course the error is something. What does the network tab of your Browser's dev tools say? – Tomalak May 26 '15 at 07:56
  • I can´t see it, I¨m in Cocoon JS Launcher and I don´t have that info, that´s the problem. – Pizzaboy May 26 '15 at 07:58

1 Answers1

3

Well, everything was a CORS thing, I fixed it with this header in the php files that receive/send data:

header("Access-Control-Allow-Origin: *");
Pizzaboy
  • 331
  • 2
  • 14