Help - Search - Members - Calendar
Full Version: Ajax Issue
Zymic Webmaster Forums > Web Design & Development > Client Side Scripting > JavaScript
The Seventh Hokage
no really good ajax tutorials to help me do what i want. i've been tinkering for a while (4 weeks) with no such luck.
i've posted on here several times trying to get some help but also no such luck. just thought i'd try one more time.


what im trying to do should be very simple.

i have a function written in PHP that i want to call with ajax. for some reason it doesn't work like i thought it would.

i have a class defined. called man with 4 variables.

all i need is to have a function of that class act on button click.

here is the pertaining code and here is the ajax code as well.

ajax

CODE
<head>




<script type="text/javascript" src="jquery.js">

function Xp()
{
var xmlhttp;//create a var for the obj
if (window.XMLHttpRequest)//if requesting an obj...
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert("Your browser does not support XMLHTTP!");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
document.write("You got the ajax to work!");
}
}
xmlhttp.open("GET","testatt.php",true);
xmlhttp.send(null);
}
</script>

</head>


class code

CODE
<?php

class man
{
var $name ;
var $Hp ;
var $Att ;
var $Def ;




function __construct($cname ,
$chp ,
$catt ,
$cdef
)
{
$this->name= $cname;
$this->Hp= $chp;
$this->Att= $catt;
$this->Def= $cdef;
}

function smack($x,$x2)
{
$hitchance=rand(1,100);
if($hitchance>=10)
{
$Dmg=$x2->Att-$x->Def;
$rdmg=rand(1,9);
$Dmg+=$rdmg;
$x->Hp-=$Dmg;
echo $Dmg." points of dmg done to ".$x->name." you have ".$x->Hp." Hp left."."</br>";
}
else
{
echo "You missed your target!"."</br>";
}

}


function powersmack($x,$x2)
{
$hitchance=rand(1,100);
if($hitchance>=50)
{
$boost=rand(5,20);
$Dmg=$x2->Att-$x->Def;
$Dmg=$Dmg*$boost;
$x->Hp-=$Dmg;
echo $Dmg." points of dmg done to ".$x->name." you have ".$x->Hp." Hp left."."</br>";
}
else
{
echo "You missed your target!"."</br>";
}
}

}



$Me=new man("Dana",100,10,7);
$You=new man("Jammie",120,20,2);

$target_of_Me= clone $You;//
$target_of_You= clone $Me;//


echo $Me->name."</br>";
echo $You->name."</br>";
echo $Me->Hp."</br>";
echo $You->Hp."</br>";

?>


once again all i want to do with this code is have the functions work on button click
The Seventh Hokage
nevermind. I'll figure it out myself dry.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.