1

这个简单的代码,我需要你的帮助..我点击这个按钮(editsubmit),它转到另一个名为trailnew.php的页面..我想检查结果是否成功......

我把它放在 trailnew.php

    <?php
    $e=isset($_POST['editsubmit']) && $_POST['editsubmit'];
    if($e)
    {
        echo "inserted";
    }
    ?>

还有剧本。。

<script>
    $("#editsubmit").click(function(event) {
        event.preventDefault();
        $("#form2").submit()
    });

    $("#form2").validate({
        debug: false,
        rules: {
            plnoedit:"required",
            pldtedit:"required",
            noboxedit:"required",
            glidedit:"required",
        },
        messages: {
            plnoedit: "Please select a pack list id..",
            pldtedit: "Please select a item id id..",
            noboxedit: "Please select a quantity id..",
            glidedit: "Please select a value id..",
        },

        submitHandler: function(form) {
            $.ajax({
                type: "POST",
                url: "trailnew.php",
                data: $('#form2').serialize(),
                cache: false,
                success: function(data) {
                    alert(data);
                }
            });

            return false;
        }
      });
</script>

第一页(trailnew.php)

<html>
<head>

  <script src="http://code.jquery.com/jquery-latest.js"></script>


 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>

 <script>


  $(document).ready(function(){

   $("#form1").validate({
         debug: false,
   rules: {
    
    plid:"required",
       },
   messages: {
    
    plid: "Please select a pack name id..",
    },
    
    submitHandler: function(form) {
 
    $.ajax
   ({
  
type: "POST",
url: "aanew.php",
data: $('#form1').serialize(),
cache: false,

success: function(response) {
    $('#result1').html(response); 
            
        }
        });
        }
  
  });

  </script>
  
</head>
<body>
<div class="result3"></div>
Packing List
</br>
<form id="form1" name="form1" action="" method="post">
<?php   

echo '<select  name="plid" id="plid">';
echo '<option value="" selected="selected">--Select the Pack Name--</option>';
$tempholder = array();
$sql="SELECT CONCAT( p.pl_no,  '_', DATE_FORMAT( p.pl_dt,  '%d/%m/%Y' ) ,  '_', g.acname ) AS plname, g.gl_id,p.pl_no,p.pl_dt,p.no_box,p.pl_id,g.acname FROM packlist p, glmast g WHERE g.gl_id = p.gl_id ORDER BY pl_dt DESC , pl_no DESC LIMIT 30";


$query = mysql_query($sql) or die(mysql_error());
$nr = mysql_num_rows($query);
for ($i=0; $i<$nr; $i++){
$r = mysql_fetch_array($query);
if (!in_array($r['plname'], $tempholder)){
$tempholder[$i] = $r['plname'];
echo "<option value='$r[pl_id]'>".$r["plname"]."</option>";
}
}

echo '</select>';

?><br/>

<input type="submit" name="delete" id="delete" value="Delete"/><br/>
<input type="submit" name="edit" id="edit" value="Edit"/><br/>
</form>


<form>
<input type="button" name="new" id="new" class="new" value="New" /><br/>
</form>

<?php
$e=isset($_POST['editsubmit']) && $_POST['editsubmit'];
if($e)
{
echo "inserted!";
}
?>

<div id="result1"></div>  

</body>

</html>

第二页(aanew.php)

<?php
session_start();
include('connect.php');
?>
<html>
<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>

 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>
<script>
$("#editsubmit").click(function(event) {
    event.preventDefault();
     $("#form2").submit()
});
 $("#form2").validate({
         debug: false,
   rules: {

    plnoedit:"required",
    pldtedit:"required",
    noboxedit:"required",
    glidedit:"required",


       },
   messages: {

    plnoedit: "Please select a pack list id..",
    pldtedit: "Please select a item id id..",
    noboxedit: "Please select a quantity id..",
    glidedit: "Please select a value id..",

        },

         submitHandler: function(form) {

    $.ajax
   ({


type: "POST",
url: "trailnew.php",
data: $('#form2').serialize(),
cache: false,
success: function(data)
        {
            window.alert(data);
        }


        });
        return false;
        }



  });


</script>
<script>

 $("#form3").validate({
         debug: false,
   rules: {

    plnodelete:"required",
    pldtdelete:"required",
    noboxdelete:"required",
    gliddelete:"required",


       },
   messages: {

    plnodelete: "Please select a pack list id..",
    pldtdelete: "Please select a item id id..",
    noboxdelete: "Please select a quantity id..",
    gliddelete: "Please select a value id..",

        },

         submitHandler: function(form) {

    $.ajax
   ({


type: "POST",
url: "trailnew.php",
data: $('#form3').serialize(),
cache: false,
success: function() {
    alert('Deleted!'); 

        }


        });
        return false;
        }



  });

</script>
</head>

        <body>
        <div id="#result1"></div>
        <?php

    $e=isset($_POST['plid']) && $_POST['plid'];
    $f=isset($_POST['edit']) && $_POST['edit'];
    if($e&&$f)
    {


    $id=$_POST['plid'];
    $query5=mysql_query("SELECT g.gl_id, p.pl_no, p.pl_dt, p.no_box, p.pl_id,g.acname
        FROM packlist p, glmast g
        WHERE g.gl_id = p.gl_id
        AND p.pl_id ='".$id."'
        LIMIT 0 , 30") or die(mysql_error());

    $row=mysql_fetch_array($query5);
    $pl_no=$row['pl_no'];
    $pl_dt=$row['pl_dt'];
    $no_box=$row['no_box'];
    $acname=$row['acname'];



    ?>
        <form name="form2" id="form2" method="post" action="">
        <P>
            <LABEL for="plnoedit">PackList No 
                      <INPUT type="text" id="plnoedit" name="plnoedit" value= <?php echo $pl_no; ?> /></LABEL><BR><BR>
                      <input type="hidden" name="myFormsName" value="form5id" id="myFormsName">
                      <input type="hidden" name="pdidedit" value=<?php echo $id; ?> id="pdidedit">
            <LABEL for="pldtedit">Date 
                      <INPUT type="text" id="pldtedit" name="pldtedit" value= <?php echo $pl_dt; ?> /></LABEL><BR><BR>

            <LABEL for="noboxedit">Box No
                      <INPUT type="text" id="noboxedit" name="noboxedit" value= <?php echo $no_box; ?> /></LABEL><BR><BR>
            <LABEL for="glidedit">Party Name
                      <INPUT type="text" id="glidedit" name="glidedit" value= <?php echo $acname; ?> /></LABEL><BR><BR>

            <INPUT type="button" id="editsubmit" name="editsubmit" value="Submit"> <INPUT type="reset">
            </P> 

        </form>
        <?php

              }

             ?>


        </body>
        </html>

我猜代码到了trainnew.php,但是警报已经加载了所有的html(整个新的新trainnew.php页面)..有什么建议吗?

来自 Trainnew.php

我使用编辑提交按钮从 aanew.php(通过 ajax)获取表单

现在我在 trailnew.php 中验证这个新表单(在 trailnew.php 中有验证代码)

现在的问题是提交处理程序上此表单的成功 ajax 调用给了我

trailnew.php 的整个新页面..我做错了什么?

我想从昨天开始解决这个问题....我想我在这里遗漏了一些重要的东西..或ajax部分..任何帮助都非常感谢!提前非常感谢..

4

2 回答 2

0
 success: function() {
    alert('Success');  
  }

为什么在不需要时提醒数据!

于 2013-05-12T06:24:07.757 回答
0

您必须停止 trailnew.php 页面才能完全执行

你的代码

<?php
$e=isset($_POST['editsubmit']) && $_POST['editsubmit'];
if($e)
{
    echo "inserted";
}
?>

你必须这样做

<?php
if(isset($_POST['editsubmit']) && $_POST['editsubmit'])
{
    die('inserted'); // this stop the page right here
}
?>
于 2013-05-12T18:06:05.140 回答