我的php页面使用ajax向另一个页面发送请求,但是以某种方式似乎无法发送该请求,我测试了update_ok.php,应该可以使用这些代码,我认为问题是来自于通过发送请求阿贾克斯。如下代码,请帮帮我。
update.php
<?php
<table>
<tr class="item">
<form action="" method="POST" name="form" id="form">
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $row_result2["id"];?>">
<input name="gp_name" type="hidden" class="normalinput" id="gp_name" value="<?php echo $row_result2["gp_name"];?>">
<input name="city" type="text" class="normalinput" id="city" size="6" value="<?php echo $row_result2["city"];?>"></td>
<td align="center"><input name="arrange" type="text" class="normalinput" id="arrange" size="10" value="<?php echo $row_result2["arrange"];?>"></td>
<td align="center"><input name="qua" type="text" class="normalinput" id="qua" size="1" value="<?php echo $row_result2["qua"];?>"></td>
<td align="center">
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $row_result2["id"];?>">
<input name="action" type="hidden" id="action" value="update">
<input type="button" name="button" value="Update" onClick="update(form);"></td>
<td align="center">
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $row_result2["id"];?>">
<input type="button" name="Submit" value="Delete" onClick="window.location.href='delete.php?id=<?php echo $row_result2['id'];?>'" />
</td>
</form>
</tr><?php }?>
</table>
index.js
function update(form){
var xml;
if(window.ActiveXObject){
xml=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xml=new XMLHttpRequest();
}
var id=form.id.value;
var city=form.city.value;
var gp_name=form.gp_name.value;
var arrange=form.arrange.value;
var qua=form.qua.value;
xml.open("GET","update_ok.php?id="+id+"&city="+city+"&gp_name="+gp_game+"&arrange="+arrange+"&qua="+qua,true);
xml.onreadystatechange=function(){
if(xml.readyState==4&&xml.status==200){
var msg=xml.responseText;
if(msg==1){
alert("Update succeed!!");
location.href='index.php';
}else{
alert("Update False");
return false;
}
}
}
xml.send(null);
}
update_ok.php
<?php
header("Content-Type: text/html; charset=utf-8");
include_once("conn/connMysql.php");
$id=$_GET['id'];
$gp_name=$_GET['gp_game'];
$arrange=$_GET['arrange'];
$city=$_GET['city'];
$qua=$_GET['qua'];
$sql=mysql_query("update gp_info set gp_name = '$gp_name', city = '$city', qua = '$qua', arrange = '$arrange' where id=".$id);
if($sql){
$reback=1;
}else{
$reback=0;
}
echo $reback;
?>