03-11-2007, 04:17 PM
Code PHP :
<?php
function createRequestObject()
{
var http;
if(window.XMLHttpRequest)
{
http = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
http = new ActiveXObject("Microsoft.XMLHTTP");
}
return http;
}
function affichage_result()
{
if(http.readyState == 4)
{
if(http.status == 200)
{
alert(http.responseText);
}
else
{
alert("<strong>N/A</strong>");
}
}
}
function bouger(x, y)
{
http = createRequestObject();
http.open('post', 'requetes_ajax.php', true);
http.onreadystatechange = affichage_result;
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send('data_x='+x+'&data_y='+y);
}
Code PHP :
<?php
if (isset ($_POST['data_x']) && isset ($_POST['data_y']))
{
//Sécurisation des variables
$data_x = sec_var($_POST['data_x']);
$data_y = sec_var($_POST['data_y']);
//Récupération d'infos sur le perso
$infos_perso = req_infos_perso($_SESSION['perso_actu']);
$id_perso = $infos_perso['id_perso'];
$coord_x = $infos_perso['coord_x'];
$coord_y = $infos_perso['coord_y'];
//On créé les coordonnées d'arrivée
$data_x = $coord_x + $data_x;
$data_y = $coord_y + $data_y;
if (!test_case_persos($data_x, $data_y) && !test_case_villes($data_x, $data_y)) //On vérifie que la place est libre
mysql_query("UPDATE persos_cda SET coord_x ='$data_x' AND coord_y ='$data_y' WHERE id_perso ='$id_perso'");
}
echo 'test';
?>