EDIT2:好的,有了这些信息,我进行了测试。我认为您正在使用一个文件,所以我设置了一个模拟 php 文件来测试。我删除了 onComplete 并使用更新设置了一个 div。这是有效的结果。让我知道它是否有帮助:
<?php
if ( isset($_GET['Nbr']) ){
// here Nbr is set, so we drop into outputting xml... you can do more before this
// and you can open a separate file, but didn't know how things were set up for you.
header('Content-Type: text/xml');
$out = $_GET['Nbr'].','
.(isset($_GET['Strt'])?$_GET['Strt']:'').','
.(isset($_GET['Bar'])?$_GET['Bar']:'').','
.(isset($_GET['FightType'])?$_GET['FightType']:'').','
.(isset($_GET['Action'])?$_GET['Action']:'');
print '<?xml version="1.0" encoding="UTF-8" standalone="yes"?'.'><span>'.htmlentities($out).'</span>';
exit();
}
?>
<html>
<head>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
function fightit(nbr,strt,bar,type,action) {
var params = "Nbr=" + nbr
+ "&Strt=" + strt
+ "&Bar=" + bar
+ "&FightType=" + type
+ "&Action=" + action;
alert(params);
// this is actually calling itself with '/t.php' and updating div01
new Ajax.Updater('div01', '/t.php', {method: 'get', parameters: params});
}
</script>
</head>
<body>
<table style="border-style:none;">
<tr>
<td style="border-style:none;">
<input style="width:150px; text-align:center;" type="button" value="Steal" onclick="stealit()" />
</td>
<td id="fightBtn" style="border-style:none;"><input style="width:150px; text-align:center;" type="button" value="Fight" onclick="fightit(0,0,0,0,0)" />
</td>
</tr>
<div id="div01"></div>
</body>
</html>
原来的:
你得到了fighttype错误,因为即使你检查了它,你仍然在检查后使用它而不重新检查($_GET['FightType']
仍然不存在)。尝试这个:
if (isset($_GET['FightType'])) {
$fighttype = $_GET['FightType'];
}
else {
$fighttype = 0;
}
$s = $fighttype;
编辑:要修复 ajax,请尝试这样的参数(您可能必须更改函数变量名称):
new Ajax.Updater('div01', 'php/fight.php', {method: 'get', parameters: {Nbr: nbr, Strt: strt, Bar: bar, FightType: type, Action: action}, onComplete: div05F})