I have php code that calls a javascript function:
onclick='fightit(0,0,0,0,0)'
Here is the javascript function:
function fightit(nbr,strt,bar,type,action) {
var params = "Nbr="+nbr;
params += "&Strt="+strt;
params += "&Bar="+bar;
params += "&FightType="+type;
params += "&Action="+action;
alert(params);
new Ajax.Updater('div01', 'php/fight.php', {method: 'get', parameters: params, onComplete: div05F});
}
When I call the function and display params I get;
Nbr=1&Strt=0&Bar=0&FightType=0&Action=0
This is what I’m suppose to get but when I use it in my php:
if (!isset($_GET['Action'])) {
$_GET['Action'] = 0;
}
if (isset($_GET['FightType'])) {
$fighttype = $_GET['FightType'];
}
else {
$fighttype = 0;
}
$s = $_GET['FightType'];
Action is set but FightType is not when I execute this line of code:
$s = $_GET['FightType'];
I get:
Undefined index: FightType in C:\wamp\www\hand\php\div08F.php on line 10
Any ideas where I’m going wrong?
EDIT2: OK, with that information, I tested out. I think you are using one file, so I set up a mock php file to test things. I removed the onComplete and set a div with the update. Here is the result that works. Let me know if it helps:
ORIGINAL:
You are getting the fighttype error, because even though you check for it, you still use it after the check without rechecking (
$_GET['FightType']still doesn’t exist). Try this:EDIT: to fix the ajax, try parameters like this (you might have to change the function variable names):