Jump to content

PHASER AJAX PHP MYSQL


craidencool
 Share

Recommended Posts

 
//In my quiz.html which is still in my localhost
function submitScore() {
    var fullname = document.getElementById("fullname").value;  
    var data="fullname="+fullname+"&Qone="+one+"&Qtwo="+two+"&Qthree="+three+"&Qfour="+three+"&score="+score;

    var request = new XMLHttpRequest();
    request.open('POST', 'http://www.musuan.net/asd/Store.php', true);
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    request.onload = function() {
      if (request.status >= 200 && request.status < 400){
        alert('yeah!');
      } else {
          alert('nah!');

      }
    };  
    request.send(data);
}  





//already uploaded in musun.net
<?php
$connection="connection.php";
$usertable="HSL_student";

$name = $_GET['fullname'];
$one = $_GET['fullname'];
$two = $_GET['fullname'];
$three = $_GET['fullname'];
$four = $_GET['fullname'];
$five = $_GET['fullname'];
$score = $_GET['fullname'];


include($connection);
$query="INSERT INTO $usertable(fullname, score, Qone, Qtwo, Qthree, Qfour, Qfive) VALUES";
$query.=" ('$name','$score','$one','$two', '$three', '$four', '$five')";
$result=mysql_query($query) or die("Error:". mysql_error());
echo "Quiz result was successfully saved.";
?>

Hey guyz I am trying to store the result of the quiz from quiz.html to a database using ajax but it wont connect and log says "XMLHttpRequest cannot load http://www.musuan.net/asd/Store.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access." please help me. thank you

Link to comment
Share on other sites

First of all, google the error and look on stackoverflow. Also not very Phaser related.
If both scripts are on the same domain you would have no issue. JSONP is used if you want to go between domains.

Short answer:
Put all the scripts on the same domain or use one of the techniques they say on stackoverflow.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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