我用ajax做了一个页面gfz.php,其中有个div叫localfresh,点击某按钮用ajax,在localfresh这个div里加载一个页面叫gncreate.php,然后实现局部刷新加载页面。其中gncreate是一个表单页面。加载gncrate.php后此页面的URL还是gfz.php现在要用gncreate提交表单,简化一下:<form name="cateform" method="post" id="cateform" action="controller.php">
<table class="att-tab" >
<tbody >
<tr>
<td>高权重:</td>
<th><input type="text" class="text-sty" placeholder="请输入高权重" required name="weighth" id="weighth"></th>
</tr>
<tr>
<td>低权重:</td>
<th><input type="text" class="text-sty" placeholder="请输入低权重" required name="weightl" id="weightl"></th>
</tr>
<tr>
<td>TAG:</td>
<<th><input type="text" class="text-sty" placeholder="请输入TAG" required name="tag" id="tag"></th>
</tr>
<button type="submit" name="submit" id="submit" class="btn btn-success" >保存</button>
</form>
其中controller.php里是(节选) <?php
ob_start();
session_start();
?>
<?php
//检测是否登录,若没登录则转向登录界面
if(!isset($_SESSION['username'])){
header("Location:login.php");
exit();
}
?>
<?php
include "conn2.php";
if(isset($_POST['submit']))
{
$weighth=$_POST['weighth'];
$weightl=$_POST['weightl'];
$tag=$_POST['tag'];
$pasql=mysql_query("SELECT * FROM `chapter` where category='$category' and chapter='$chapter' and chapterlist='$chapterlist'");
$rowpa=Mysql_num_rows($pasql);
if($rowpa>0){
echo '<script>alert("此章节已存在!若修改请返回到总攻略页面修改!");window.location="gfz.php";</script>';
}
else{
$reatten=mysql_query("INSERT INTO `attention` (`category`,`chapter`,`chapterlist`,`weighth`,`weightl`,`tag`,`npcs`,`needs`,`npcg`,`needg`,`mainattention`,`skillstate`) VALUES ('$category','$chapter','$chapterlist','$weighth','$weightl','tag','$npcs','$needs','$npcg','$needg','$mainattention','$skillstate');"); echo '<script>alert("保存成功!");window.location="gfz.php";</script>';
}
}
?>我现在只能在控制器即controller.php里通过window.location跳转到gfz.php页面,但是无法跳转到含有gncreate.php的gfz.php页面。
该怎样跳到含有gncreate.php的gfz.php页面?或者不刷新直接提交数据到数据表,含有gncreate.php的gfz.php页面不刷新?
然后if(isset($_POST['submit']))
{
$weighth=$_POST['weighth'];
$weightl=$_POST['weightl'];
$tag=$_POST['tag'];
$pasql=mysql_query("SELECT * FROM `chapter` where category='$category' and chapter='$chapter' and chapterlist='$chapterlist'");
$rowpa=Mysql_num_rows($pasql);
if($rowpa>0){
echo 'yes';
}
else{
$reatten=mysql_query("INSERT INTO `attention` (`category`,`chapter`,`chapterlist`,`weighth`,`weightl`,`tag`,`npcs`,`needs`,`npcg`,`needg`,`mainattention`,`skillstate`) VALUES ('$category','$chapter','$chapterlist','$weighth','$weightl','tag','$npcs','$needs','$npcg','$needg','$mainattention','$skillstate');");
echo 'no';
}
}
?>