jquery用添加按钮把数据传送给PHP页面
2012-07-27 17:27
351 查看
先建一个HTML文件,命名为add.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<title>添加按钮</title>
/*要添加好jquery库*/
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
</head>
<body>
<form id="add_form">
<div>
<input type="text" name="caizhong" value="双色球" id="qg_ssq"/>
<input type="checkbox" name="qihao" value="20100727" id="qihao" />
</div>
<div>
<input type="submit" name="add_submit" value="添加" id="add_submit" />
</div>
</form>
<script type="text/javascript">
$('form#add_form').submit(function() {
var caizhong=$('input#qg_ssq').val();
var qihao=$('input#qihao').val();
alert($(this).serialize());
$.ajax(
{
url: 'add_data.php',
method: 'get',
data: $(this).serialize(),
success: function()
{
window.open("add_data.php?caizhong="+caizhong+"&qihao="+qihao);
}
});
});
</script>
</body>
</html>
再建一个php页面,命名为:add_data.php
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<?php
$caizhong=$_GET['caizhong'];
$qihao=$_GET['qihao'];
echo $caizhong;
echo $qihao;
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<title>添加按钮</title>
/*要添加好jquery库*/
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
</head>
<body>
<form id="add_form">
<div>
<input type="text" name="caizhong" value="双色球" id="qg_ssq"/>
<input type="checkbox" name="qihao" value="20100727" id="qihao" />
</div>
<div>
<input type="submit" name="add_submit" value="添加" id="add_submit" />
</div>
</form>
<script type="text/javascript">
$('form#add_form').submit(function() {
var caizhong=$('input#qg_ssq').val();
var qihao=$('input#qihao').val();
alert($(this).serialize());
$.ajax(
{
url: 'add_data.php',
method: 'get',
data: $(this).serialize(),
success: function()
{
window.open("add_data.php?caizhong="+caizhong+"&qihao="+qihao);
}
});
});
</script>
</body>
</html>
再建一个php页面,命名为:add_data.php
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<?php
$caizhong=$_GET['caizhong'];
$qihao=$_GET['qihao'];
echo $caizhong;
echo $qihao;
?>
相关文章推荐
- jquery用添加按钮把两个数据传送给PHP页面
- 用html、jquery、php编写新闻后台管理页面,动态添加新闻数据并实现数据的增删改查功能
- jquery,从后台查数据,给页面上添加树形。
- jQuery提交数据给php,serialize()方法提交所有数据,不发生页面跳转
- php+ajax+jquery 定时刷新页面数据
- 页面显示时间日期,通过jquery动态向表格添加数据
- velocity页面下,使用jQuery实现点击添加按钮添加一行输入框
- jQuery提交数据给php,serialize()方法提交所有数据,不发生页面跳转
- jQuery 中的 Ajax 全局事件 当用户点击页面上某一按钮请求数据时,在页面上显示 loading... ,页面加载完成后隐藏
- 使用jQuery在移动页面上添加按钮和给按钮添加图标
- PHP AJAX数据添加(jquery)
- [置顶] php jQuery把后台返回的json数据赋值给页面标签
- repeater实现样式设置,并添加删除按钮,参考课上老师做的案例。数据表添加字段status,使用repeater实现禁用与启用。repeater添加编辑按钮,和Edit.aspx页面。
- 在页面中添加jquery的自动补全功能,传输数据采用JSON
- 手机端页面下拉加载数据的笨办法--点击按钮添加数据
- 在页面中添加jquery的自动补全功能,传输数据采用JSON
- .Net 点击按钮实现动态添加行并保持页面的数据不变
- 结合php与JQuery仅用两个页面对数据库的数据进行增删改
- jQuery 实时保存页面动态添加的数据的示例
- jquery接收PHP传送过来的JSON格式数据以及处理。