Im trying to make a realtime game with no page refresh. The problem is that i dont know what to do next or how to configure ajax script to update the mysql database when the player is movine over the map.
Here is the ajax code im trying to use.
//calling ajax to update player location when he move around
function send(url){
var request;
try{
request= new XMLHttpRequest();
} catch (e){
try{
request= new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
request= new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
alert("Your browser broke!");
return false;
}
}
}
request.onreadystatechange = function(){
if(request.readyState == 4){
//I dont know what to add here :-(
}
}
request.open("GET", url, true);
request.send(null);
}
send("update_location.php?newX="+ toX + "&newY=" + toY)
update_location.php
<?php
$new_x=$_GET['newX'];
$new_y=$_GET['newY'];
//echo"$new_x , $new_y";
$update_loc=mysql_query("UPDATE users SET location_x='$new_x' WHERE username='admin'");
?>
The main ideea is that when the player moves anywhere over the map the ajax updates new x and y values into the database.I dont need any button or jquery code added,i think ajax will work fine if somebody get me a hand doing this.
P.S. toX and toY are javascript vars wich i transformed to php vars so i can update them to mysql datavase.If somebody could help me do this i would really appreciate!