Jump to content

phaser - mighty - ajax-php-mysql


enigmatico
 Share

Recommended Posts

Hi, I want to connect with a database to save the scores, but, on first, I'm making a test.

I'm trying with this sample code to know if I could receive simply "text" request,

var pause_ajax = this.game.add.text(this.game.world.centerX, this.game.world.centerY+30, "connection");
        pause_ajax.inputEnabled = true;
        pause_ajax.events.onInputUp.add(function () {

                  var ajaxUrl = "http://www.anotherurlnotinmighty.es/php.php";

                  $.ajax({
                    url: ajaxUrl,
                    
                    dataType: "html",
                    method: "post",
                    beforeSend: function() {

                    },
                    success: function() {
                        alert("work");
                    },
                    error: function(){
                        alert("error")
                    }
                  });

        });

The php file is on another server. When I click the label, this makes the connection but it don't recive anything. ResponseText=""

 

php.php

<?php
session_start();
print "test";

?>

 

jQuery is correctly imported on my project.

 

There are any other best option to save the scores on dataBase?

 

Thanks

Link to comment
Share on other sites

Hi,

there are 2 options: 
1) set header to allow mightyeditor.mightyfingers.com access www.anotherurlnotinmighty.es
add the header("Access-Control-Allow-Origin: http://mightyeditor.mightyfingers.com") to your script:

<?php
header("Access-Control-Allow-Origin: http://mightyeditor.mightyfingers.com");
session_start();
print "test";

more info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

2) use jsonp - requires a little more scripting: http://www.sitepoint.com/jsonp-examples/

Link to comment
Share on other sites

On 28/2/2016 at 1:00 PM, stauzs said:

Hi,

there are 2 options: 
1) set header to allow mightyeditor.mightyfingers.com access www.anotherurlnotinmighty.es
add the header("Access-Control-Allow-Origin: http://mightyeditor.mightyfingers.com") to your script:


<?php
header("Access-Control-Allow-Origin: http://mightyeditor.mightyfingers.com");
session_start();
print "test";

more info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

2) use jsonp - requires a little more scripting: http://www.sitepoint.com/jsonp-examples/

I've used the option 1, it works! Thanks!!

Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...