0

我有这段代码可以向数据库添加新记录。运行后,我需要使用 jQuery 将用户重定向到成功页面。

  <? session_start();
include "sec.php";
?>
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../scripts/forms.css">
<head>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/datetimepicker.js"></script>
<script language="javascript">
    $(document).ready(function() {
        $("[required=true]").after("<span></span>");
        $("#submit").click(function(){
            var error=false;
            $("span").text("");
            $("[class~=Red]").removeClass("Red");
            if(trim($("#VisaDocNo").val())==""){
                $("#VisaDocNo").addClass("Red");
                error=true;
            }
            if(trim($("#VisaCountry").val())==""){
                $("#VisaCountry").addClass("Red");
                error=true;
            }
            if(trim($("#CustNo").val())==""){
                $("#CustNo").addClass("Red");
                error=true;
            }
            $("[class=Red]").eq(0).focus();
            return !error;
        });
    });
    function trim(x) {
        return x.replace(/^\s+|$\s+/,'');
    }
    function isEmail(str)
    {
        var regex = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
        return regex.test(str);
    }
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>اضافة تأشيرة جديدة</title>
</head>
<body topmargin="0">
<?php
include("../functions/connect.php");
if(!empty($action)){
$sql="select * from visa where VisaNo='$VisaNo'";
$q=mysql_query($sql);
$n=mysql_num_rows($q);
if($n==1 ){
echo  "<script>window.alert('عفوا ,,, السجل مسجل ممسبقا.')</script>";
}
else{
if($ActFollow!=1)
    $ActFollow=0;

$sql="insert into visa
(VisaNo,VisaDate,CustNo,VisaDocNo,VisaCountry,VisaDoneDate,VisaType,SysUser,Notify,Notes,FileNo)
 values
(0,CURDATE(),'$CustNo','$VisaDocNo','$VisaCountry','$VisaDoneDate','$VisaType','$SysUser','$Notify','$Notes','$FileNo')";
$q=mysql_query($sql);
if($q){
echo "<script>window.alert('تمت اضافة سجل جديد.')</script>";
  $insert_page = mysql_insert_id(); 
  echo "<script type='text/javascript'>window.location='editvisa.php?change=$insert_page'</script>";  
}
else{
echo  "<script>window.alert('خطأ في اضافة سجل جديد.')</script>";
}
}
}

include "visamenu.php";
?>
<div class="theform">
<table width="777" border="0" align="center" cellspacing="1" >
<form action="" method="post" name="visa" dir="rtl">
        <tr >
          <td colspan="2" class="xtt" height="30"><div align="center">اضافة سجل جديد</div></td>
        </tr>
        <tr>
          <td width="553" align="right" class="xtd">
          <input id="preview" name="CustNo" required="true" dir="rtl" value="<?=$r[CustomersNo]?>" size="50" readonly="readonly">
<button type="button" name="choice" onClick="window.open('chs_customer.php','popuppage','width=900,toolbar=0,resizable=1,scrollbars=no,height=500,top=100,left=100');">عرض الزبائن</button>
          </td>
          <td align="right"  class="xtx"><div align="right">اسم الزبون</div></td>
        </tr>
        <tr>
          <td align="right" class="xtd"><input name="VisaDocNo" required="true" type="text" id="VisaDocNo" dir="rtl" lang="ar" size="50" maxlength="40" /></td>
          <td align="right" class="xtx"><div align="right">رقم الفيزا</div></td>
        </tr>
        <tr>
          <td align="right" class="xtd"><input name="VisaCountry" required="true" type="text" id="VisaCountry" dir="rtl" lang="ar" size="50" maxlength="40" /></td>
          <td align="right" class="xtx"><div align="right">دولة الذهاب - التأشيرة</div></td>
        </tr>
                <tr>
          <td align="right" class="xtd"><input name="VisaDoneDate" type="text" id="Date" dir="rtl" lang="ar" size="50" maxlength="40" />
          <a href="javascript:NewCal('Date','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
          </td>
          <td align="right" class="xtx"><div align="right">تاريخ دور التأشيرة</div></td>
        </tr>
        <tr>
          <td align="right" class="xtd"><input name="VisaType" type="text" id="VisaType" dir="rtl" lang="ar" size="50" maxlength="40" /></td>
          <td align="right" class="xtx"><div align="right">نوع الفيزا</div></td>
        </tr>
        <tr>
          <td align="right" class="xtd"><input name="SysUser" type="text" readonly="readonly" id="SysUser" value="<? echo $_SESSION[aname]?>" size="50" maxlength="40"  dir="rtl"/></td>
          <td align="right" class="xtx"><div align="right">الموظف المسؤول </div></td>
        </tr>
        <tr>
          <td align="right" class="xtd"><input name="Notify" type="checkbox" id="Notify" value="1"/></td>
          <td align="right" class="xtx"><div align="right">تنبيه</div></td>

        </tr>
        <tr>
          <td align="right" class="xtd"><input name="Notes" type="text" id="Notes" size="50" maxlength="40"  dir="rtl"/>
          </td>
          <td align="right" class="xtx"><div align="right">ملاحظات </div></td>
          </tr>
          <tr>
          <td align="right" class="xtd"><input name="FileNo" type="file" disabled="disabled" id="FileNo" size="41" maxlength="40"  dir="rtl"/></td>
          <td align="right" class="xtx"><div align="right">ملفات مرفقة</div></td>
          </tr>        <tr>
          <td align="right" class="xtd"><label>
            <input type="submit" name="Submit" value="اضافة التأشيرة" onClick="return validate()">
          </label></td>
          <td class="xtd"><input name="action" type="hidden" id="action" value="done" /></td>
        </tr>
      </form>
</table>
</div>
</body>
</html>

添加新记录后,我们使用此方法重定向到另一个页面:

      $insert_page = mysql_insert_id(); 
  echo "<script type='text/javascript'>window.location='editvisa.php?change=$insert_page'</script>";  

如何使用 jQuery 重定向?

4

1 回答 1

0

使用这样的代码

<?php
$insert_page = mysql_insert_id(); 
?>
<script type='text/javascript'>
window.location='editvisa.php?change=<?php echo $insert_page;?>'
</script>;  
于 2012-04-11T06:13:00.123 回答