Am o intrebare in legatura cu o problema peste care dau cand fac un script php.Am o functie javascript ce foloseste ajax.
Cod: Selectaţi tot
<script type="text/javascript" language="JavaScript">
// Aici este cod JavaScript;
function changedState()
{
var skill = document.getElementsByName("skill").value;
var id = document.getElementsByName("id").value;
if(xmlHttp.readyState==4)
{
document.getElementById("mission_result").innerHTML=xmlHttp.responseText + "skill = " + skill + "id = " + id ;
}
}
function check_mission()
{
var skill= document.getElementById("skill").value;
var id= document.getElementById("id").value;
var str = 'm='+ skill +'&id='+ id;
xmlHttp=browserValidator();
if(xmlHttp==null)
{
alert('Browserul dumneavoastra nu suporta aceasta aplicatie, va rugam instalati o versiune compatibila. (Exemplu: Firefox)');
return;
}
var url="validate_m.php";
xmlHttp.onreadystatechange=changedState;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
xmlHttp.setRequestHeader("Content-Length", str.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(str);
}
function browserValidator()
{
var xmlHttp;
try
{
// Numai pentru browserele Firefox, Opera 8.0+, Safari;
xmlHttp=new XMLHttpRequest();
}
catch(e)
{
try
{
// Numai pentru browserul Internet Explorer;
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
// Alte browsere.
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
// Eroare daca browserul nu este compatibil cu aplicatie.
alert('Browserul dumneavoastra nu suporta aceasta aplicatie, va rugam instalati o versiune compatibila. (Exemplu: Firefox)');
return false;
}
}
}
return xmlHttp;
}
</SCRIPT>
+ codul
Cod: Selectaţi tot
<table cellpadding="0" cellspacing="0" border="1" bordercolor="#000000">
<tr>
<td>Number</td><td>Description</td><td>Xp Given</td><td>Validate</td></tr>
<? if ($p['mission1_done'] == 0){?>
<Tr>
<Td>1.</td><td> Account Activation </td><td> 50 xp points</td><td><?if ($p['mission1_done'] == 0){?><a href="validate_m.php?m=1">VALIDATE</a><? } else {?>COMPLETED<?}?><input type="hidden" name="skill" value="1"><input type="hidden" name="id" value="1"></td></tr>
</table>
<a href="#" onClick="check_mission();">Check Mission</a><div id="mission_result"></div>
Problema este cand apas check_mission ar trebuii sa imi execute in ajax validate_m.php?m=1&id=1.
Codul pt validate_m.php este urmatorul :
Cod: Selectaţi tot
<?php
include('common.php');
$do = $_GET['m'];
$id = $_GET['id'];
switch($do) {
case '1':
$mis = "mission".$do."_done";
$valid = $p[$mis];
if ($valid == 0)
{
if ($p['este_activat'] == 1){
mysql_query("UPDATE `user` set `".$mis."` = 1 where `id` = '".$id."' LIMIT 1;");
mysql_query("UPDATE `user` set `experience` = `experience` + 50 where `id` = '".$id."' LIMIT 1;");
echo " Mission Validated";
}
}
else {echo"Ai facut deja misiunea";}
break;
default:
echo"id-ul este $id si skill-ul $do";
break;
}
?>