日期:2014-05-17 浏览次数:20416 次
?
<input name="writer" id="writer" type="text" value="" />
<input name="pass" id="pass" type="password" value="" />
<input type="submit" name="button" id="button" value="提交" />
<!--这里不需要form,因为提交时call一个函数
<script type="text/javascript">
$(document).ready(function(){????????//DOM的onload事件处理函数
??$("#button").click(function(){??????????//当按钮button被点击时的处理函数
????postdata();??????????????????????????????????????//button被点击时执行postdata函数
??});
});
function postdata(){?????????????????????????????//提交数据函数
??$.ajax({?????????????????????????????????????????????????//调用jquery的ajax方法
????type: "POST",?????????????????????????????????????//设置ajax方法提交数据的形式
????url: "ok.php",??????????????????????????????????????//把数据提交到ok.php
????data: "writer="+$("#writer").val()+"&pass="+$("#pass").val(),????//输入框writer中的值作为提交的数据
????success: function(msg){?????????????????//提交成功后的回调,msg变量是ok.php输出的内容。
??????alert("数据提交成功");?????????????????????//如果有必要,可以把msg变量的值显示到某个DIV元素中
????}
??});
}
</script>
ok.php文件
require "config.php";
require "conn.php";
$writer=$_POST['writer'];
$pass=$_POST['pass'];
mysql_query("insert into user values(0,'$writer','$pass')",$db);
//echo $_POST['writer'];
?>