建议 LZ 还是仔细学习一下前端的知识sample.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML</title>
<script src="jquery.js"type="text/javascript"></script>
<script type="text/javascript">
var data={name:'orange',age:20,sex:'male'};
var url='index.php';
jQuery(document).ready(function(){
jQuery('#submit').click(
function(){
jQuery.post(url,data,function(result){
if(result.code==0){
alert('插入成功');
}else{
alert('插入失败,错误信息:'+result.msg);
}
},'json').error(function(){
alert("网络不通或者服务器执行失败");
});
}
);
});
</script>
</head>
<body>
<input type="button" id="submit" value="提交" />
</body>
</html>
index.php
<?php
function insert(){
$ret = array('code'=>1,'msg'=>'数据不合法');
extract($_POST);
/*
* 执行逻辑
* 插入数据库 $name $age $sex
*/
$ret['code'] = 1;
echo json_encode($ret);
}
insert();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML</title>
<script src="jquery.js"type="text/javascript"></script>
<script type="text/javascript">
var data={name:'orange',age:20,sex:'male'};
var url='index.php';
jQuery(document).ready(function(){
jQuery('#submit').click(
function(){
jQuery.post(url,data,function(result){
if(result.code==0){
alert('插入成功');
}else{
alert('插入失败,错误信息:'+result.msg);
}
},'json').error(function(){
alert("网络不通或者服务器执行失败");
});
}
);
});
</script>
</head>
<body>
<input type="button" id="submit" value="提交" />
</body>
</html>
index.php
<?php
function insert(){
$ret = array('code'=>1,'msg'=>'数据不合法');
extract($_POST);
/*
* 执行逻辑
* 插入数据库 $name $age $sex
*/
$ret['code'] = 1;
echo json_encode($ret);
}
insert();
姓名:<input type="text" name="name" /><br />
年龄:<input type="text" name="age" /><br />
性别:<input type="text" name="sex" /><br />
<input type="submit" value="提交" />
</form>//index.php代码
$name=$_POST['name'];
$age=$_POST['age'];
$sex=$_POST['sex'];
function insert($name,$age,$sex){
echo $name.$age.$sex;
}
insert($name,$age,$sex);