下面问题是从这个问题延迟出来的:如何让传参又不跳转网页?
下面的index.htm提交以后,通过addpage.php生成了result.htm,但没有得到folder和page的数据,数据为空白。请问要怎么设置?index.htm代码如下<html>
<head>
<title>ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>
<script type="text/javascript" >
$(function(){
$("#config").submit(function(){
$.ajax({
type:"GET",
url:"addpage.php",
});
});
});
</script>
</head>
<body>
<form name="config" method="post" id="config">
<div class="infotitle">主目录:</div>
<input name="folder" type="text"/>
<div class="infotitle">页面名称:</div>
<input name="page" type="text"/>
<div class="submit">
<button type="submit" id="submit">确定</button>
</div>
</form>
</body>
</html>
addpage.php代码如下
<?php$folder=$_POST['folder'];
$page=$_POST['page'];
$file=fopen('result.htm','w');
fwrite(
$file,
"文件夹为:".$folder.'<br>'.
"模板页为:".$page.'<br>'
);
fclose($file);
?>
下面的index.htm提交以后,通过addpage.php生成了result.htm,但没有得到folder和page的数据,数据为空白。请问要怎么设置?index.htm代码如下<html>
<head>
<title>ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="http://localhost/leb/auto/js/jquery-latest.js"></script>
<script type="text/javascript" >
$(function(){
$("#config").submit(function(){
$.ajax({
type:"GET",
url:"addpage.php",
});
});
});
</script>
</head>
<body>
<form name="config" method="post" id="config">
<div class="infotitle">主目录:</div>
<input name="folder" type="text"/>
<div class="infotitle">页面名称:</div>
<input name="page" type="text"/>
<div class="submit">
<button type="submit" id="submit">确定</button>
</div>
</form>
</body>
</html>
addpage.php代码如下
<?php$folder=$_POST['folder'];
$page=$_POST['page'];
$file=fopen('result.htm','w');
fwrite(
$file,
"文件夹为:".$folder.'<br>'.
"模板页为:".$page.'<br>'
);
fclose($file);
?>
<script type="text/javascript" > $(function(){
$("#config :submit").click(function(){
$.post('addpage.php', $("form").serialize());
});
});
</script>
只是方式使用了GET,你自己接收却是POST
<script type="text/javascript" >
$(function(){
$("#config").submit(function(){
$.ajax({
type:"POST",
url:"addpage.php",
data:"folder=1&page=2"
});
});
});
</script>
我要传的是form里面自己输入的值,不是固定值
$("#submit").click(function(){
$.post('addpage.php', $("form").serialize());
});
});
</script>这个不行肯定你其它地方有问题了