初学script+ajax 数据提交问题
HTML中的内容
............
<div>密码:
<input type="text" name="pw" value="<?php echo $arr['pw'];?>">
</div>
<div>邮箱:
<input type="text" name="email" size="40" value="<?php echo $arr['email'];?>">
</div>
............
<script>
function submit(i)
{
var sendData="";
if(i=="1"){sendData='{"action":"'+i+'","pw":'+getElementByName+',"email":'+getElementByName+':}';}
$.ajax({
timeout:5000,
type:"POST",
url:"edit_server.php",
data:sendData,
success:function(data)
{
getData(1); //这是一个函数,用来打开一个页面。
}
});
}
</script>
edit_server.php中的内容:
require_once "functions.php";
connectDb();
if($_GET['action']=="1")
{
$pw = $_POST['pw'];
$email = $_POST['email'];
mysql_query("UPDATE basic_information SET pw = '$pw',email = '$email');
if(mysql_errno()){
echo mysql_error();
}else{
getData(1);
}
}