21,886
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
$("#submit").click(function(){
$.ajax({url: 'p.php',
type: 'GET',
dataType: 'html',
timeout: 1000,
error: function(){alert('Error');},
success: function(result){alert(result);}
});
return false;
});
</script>
<!-- 当前页面xxx.php -->
<?php
if(isset($_GET['new'])){
$sql="……";
……
}
?>
<form name="form" action="xxx.php">
<input type="button" name="new" value="新生入库" onclick="location.href='xxx.php?new=1'" />
</form>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6/jquery.js"></script>
</head>
<body>
<input type="button" id="submit" value="提交">
<script type="text/javascript">
$("#submit").click(function(){
$.ajax({url: 'p.php',
type: 'GET',
dataType: 'html',
timeout: 1000,
error: function(){alert('Error');},
success: function(result){alert(result);}
});
return false;
});
</script>
</body>
</html>
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//mysql_select_db('mydb');
//mysql_query("INSERT INTO mytable (product) values ('kossu')");
exit("ok");
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> ajax 提交 </title>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>
<input name="txt_name" id="txt_name" type="text" value="">
<input name="txt_age" id="txt_age" type="text" value="">
<input type="button" onclick="btnClick();" value="提交">
<script type="text/javascript">
function btnClick(){
var txtName = $('#txt_name').val();
var txtAge = $('#txt_age').val();
dataVal={txt_name:txtName,txt_age:txtAge};
$.ajax({
type: "GET",
url: "a.php",
data:dataVal,
// data: "name=John&location=Boston",
success: function(msg){
alert(msg);
}
});
}
</script>
</body>
</html>
//打印出从a.html传递过来的表单数据,用来测试用,
//实际中做相应处理,如提交到表操作等
var_dump($_GET);