简体   繁体   English

如何在JavaScript中在后台调用另一个页面

[英]How to call another page in background in JavaScript

I have a button in enroll.html . 我在enroll.html中有一个按钮。 The code of the page is as follows : 该页面的代码如下:

<HTML>
<HEAD>
<META http-equiv=Content-Language content=en-us>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<style TYPE="text/css">
    <!-- BODY               { font-family:arial,helvetica; margin-left:5; margin-top:0}
            A                   { color:#FF5500; text-decoration:underline}
            A:hover,A:active    { color:#0055FF; text-decoration:underline}
        -->
</style>
<Script Language="JavaScript">
<!--
function inStrGrp(src,reg)
{
    var regex=new RegExp("[" + reg + "]","i");
    return regex.test(src);
}

function check()
{   
    var uname=document.scan.elements[0].value
    var bError=false

    if (uname.length==0)
    {
        window.alert("Name is required.\n")
        return false
    }
    if (uname.indexOf("\\")>=0)
        bError=true

    if (inStrGrp(uname,'/.:*?"<>| '))
        bError=true

    if (bError)
    {
        window.alert('User name can not contain the following characters:\n \\/. :*?"<>|\n')
        return false
    }
    else 
        return true  
}
-->
</Script>

<title>Enroll New Fingerprint.</title>
</HEAD>
<BODY onload="document.scan.name.focus();">
<center>
<table border="0" width="800">
  <tr>
    <td width="100%" colspan="3">
      <p>&nbsp;</p>
      <p><u><b>Online Demonstration</b></u></p>
      <div align="center">
      <table border="1" width="100%" height="260">
        <tr>
          <td width="20%" align="center" rowspan="2">
                <p>&nbsp;</p>
                <p><font color="#0055FF">Enroll</font></p>
              <p><a href="logon.asp">Logon</a></p>
              <p>&nbsp;</p>
          </td>
          <td width="80%" height="30">
              <b><i>Enroll Finger</i></b>
          </td>
         </tr>
         <tr>
          <td width="80%">
      <p>Thanks for your registration. You can enroll two fingers for the name you registered.</p>

      <form name="scan" method="POST" action="http://10.11.201.170/data/sultan/enroll.asp" onsubmit="return check()">
        <p>Please input your name: <input type="text" name="name" size="20">&nbsp;&nbsp;&nbsp;&nbsp;</p>
        <p>If you want to enroll 2 fingers, please check the box. <input type="checkbox" name="chk2Finger" value="2">&nbsp;&nbsp;</p>
        <p>&nbsp;
        <input type="submit" value="   Enroll   " name="btnEnroll"></p>
      </form>

            </td>
        </tr>
      </table>
      </div>
      <p>&nbsp;</p>
    </td>
  </tr>
  <tr>
    <td width="100%" colspan="3">
      <p align="center"><small>Copyright © 2004 Futronic
      Technology Company Limited. All Rights Reserved.</small></td>
  </tr>
</table>
</center>
</BODY>
</HTML>

When I press Enroll Button , I want to load a page named verify.asp in background . 当我按下“注册按钮”时,我想在后台加载一个名为verify.asp的页面。 How can I do that ? 我怎样才能做到这一点 ?

The code of verify.asp is as follows : verify.asp的代码如下:

<HTML>
<HEAD>
<META http-equiv=Content-Language content=en-us>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<style TYPE="text/css">
    <!-- BODY               { font-family:arial,helvetica; margin-left:5; margin-top:0}
            A                   { color:#FF5500; text-decoration:underline}
            A:hover,A:active    { color:#0055FF; text-decoration:underline}
        -->
</style>
<Script Language="VBScript" Src="GetInfo.vbs">
</Script>
<title>Enroll Fingerprint.</title>
</HEAD>
<BODY Onload="GetLearnModel()";>
<center>
<table border="0" width="800">
  <tr>
    <td width="100%" colspan="3">
      <p>&nbsp;</p>
      <p><u><b>Online Demonstration</b></u></p>
      <div align="center">
      <table border="1" width="100%" height="260">
        <tr>
          <td width="20%" align="center" rowspan="2">
                <p>&nbsp;</p>
                <p><a href="enroll.asp">Enroll</a></p>
              <p><a href="logon.asp">Logon</a></p>
              <p>&nbsp;</p>
          </td>
          <td width="80%" height="30">
              <b><i>Enroll Finger</i></b>
          </td>
         </tr>
         <tr>
          <td width="80%">
        <Form name="scan" method="Post" action="famenroll2.asp?name=<%=Request("name")%>&check=<%=Request("check")%>&finger=<%=Request("finger")%>">
        <Input type="hidden" name="LearnModel" value="">
        <Input type="text" name="SlNo" value="">
        </Form>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
            <p><font size="5" color="#ff0000"><%=Request.Form("SlNo")%></font><font size="5">&nbsp;&nbsp;Enroll Successfully!</font></p>
            </td>
        </tr>
      </table>
      </div>
      <p>&nbsp;</p>
    </td>
  </tr>
  <tr>
    <td width="100%" colspan="3">
      <p align="center"><small>Copyright © 2004 Futronic
      Technology Company Limited. All Rights Reserved.</small></td>
  </tr>
</table>
 <% Dim Conn,strSQL,objExec,NumOfRecords,se_name,finger
            cust_no=Request.QueryString("name")
            Set Conn = Server.Createobject("ADODB.Connection")  
            Conn.Open "Driver={Oracle in XE};DBQ=xe;UID=biotpl;PWD=biotpl;"           

            'Query for the customer entry in FP_ENROLL Table
            strSQL2 = "INSERT INTO TEST  values(1,'OS')" 

                Set objExec = Conn.Execute(strSQL2)

            'Query for the no of fingers to be taken for a customer in FP_FINGER_SETUP Table                  
            'Set objExec = Conn.Execute("select FINGURE_NO NoF from BIOTPL.FP_FINGER_SETUP where USER_TYPE=" & Request.QueryString("cust_type") )  
            'NumOfFingers = objExec("NoF")

            'Conn.Close()  
             Set objExec = Nothing  
             Set Conn = Nothing  
 %>
</center>
</BODY>
</HTML>

Ajax can be used to load a page in background. Ajax可用于在后台加载页面。 jQuery supports AJAX functionality and it is easier than what described in the first link. jQuery支持AJAX功能,并且比第一个链接中描述的要容易。 If your intention is to Verify an enrollment, you need to parse the reply coming out of the AJAX request. 如果您打算验证注册,则需要解析AJAX请求中的答复。 An earlier answer on parsing can be found here . 可以在这里找到有关解析的更早答案。

The essential steps are 基本步骤是

  1. Add an id to your form submit button (say 'enroll') 在表单提交按钮中添加一个ID(例如“注册”)

  2. Include jQuery JavaScript library to your project by adding the following in the header < script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>‌ 通过在标头< script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>‌添加以下内容,将jQuery JavaScript库添加到您的项目中。 < script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>‌

3.Within script tag, use a similar methodology as below. 3.在script标签内,使用如下类似的方法。

$("#enroll").click(function(){ 
     $.ajax({
        url: "verify.asp", 
        success:   function(result){ 
                      /* Parse the result and do whatever you want to do here */
        }
      });
});

Add an Id in this Line 在此行中添加一个ID

<input type="submit" value="   Enroll   " name="btnEnroll">

So it becomes : 变成:

<input type="submit" value="   Enroll   " id="buttonEnroll" name="btnEnroll">
<div id="result"></div>

and Than Write this Script 并且比写这个剧本

    <script>
       $("#buttonEnroll").on('click',function(e){
           e.preventDefault();
           $( "#result" ).load( "verify.asp" );
           alert("Page loading completed");  
       });
    </script>

#result is for loading that page in result id div.

Hope Helps ! 希望有帮助!

Add this inside your header tag 将此添加到标题标签中

<script   src="https://code.jquery.com/jquery-2.2.3.min.js"   integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="   crossorigin="anonymous"></script>

 //1st way:: function doFunction(event) { event.preventDefault(); //here you can load verify.aspx by using $("#resultdiv").load("verify.aspx", {}, function (data) { alert("loading complete"); }); } //2nd way: //By using ajax call $('#enroll').on('click', 'input[type="submit"]', function(e){ e.preventDefault(); $.post('http://mywebsite/verify.aspx',{ 'data': $('#txt_search').val() } ,function(data) { console.log(data); // this would show you the returned data. }); }); 
 You can do it in 2ways: HTML: 1st way:: ========= Add onclick to your enroll button. <input type="submit" value="Enroll" onclick="doFunction();" id="enroll" name="btnEnroll"></p> <div id="resultdiv"> </div> 2nd way: ======== By using ajax call 

Here is modified enroll.html with modified Js 这是修改后的Js修改后的enroll.html

 <HTML> <HEAD> <META http-equiv=Content-Language content=en-us> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <style TYPE="text/css"> <!-- BODY { font-family:arial,helvetica; margin-left:5; margin-top:0} A { color:#FF5500; text-decoration:underline} A:hover,A:active { color:#0055FF; text-decoration:underline} --> </style> <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> <title>Enroll New Fingerprint.</title> </HEAD> <BODY> <center> <table border="0" width="800"> <tr> <td width="100%" colspan="3"> <p>&nbsp;</p> <p><u><b>Online Demonstration</b></u></p> <div align="center"> <table border="1" width="100%" height="260"> <tr> <td width="20%" align="center" rowspan="2"> <p>&nbsp;</p> <p><font color="#0055FF">Enroll</font></p> <p><a href="logon.asp">Logon</a></p> <p>&nbsp;</p> </td> <td width="80%" height="30"> <b><i>Enroll Finger</i></b> </td> </tr> <tr> <td width="80%"> <p>Thanks for your registration. You can enroll two fingers for the name you registered.</p> <form name="scan" > <p>Please input your name: <input type="text" name="txtName" size="20" id="txtname">&nbsp;&nbsp;&nbsp;&nbsp;</p> <p>If you want to enroll 2 fingers, please check the box. <input type="checkbox" name="chk2Finger" value="2">&nbsp;&nbsp;</p> <p>&nbsp; <input type="button" value="Enroll" name="btnEnroll" id="btnEnroll"></p> </form> </td> </tr> </table> </div> <p>&nbsp;</p> </td> </tr> <tr> <td width="100%" colspan="3"> <p align="center"><small>Copyright © 2004 Futronic Technology Company Limited. All Rights Reserved.</small></td> </tr> </table> </center> </BODY> </HTML> <script type="text/javascript"> function inStrGrp(src,reg) { var regex=new RegExp("[" + reg + "]","i"); return regex.test(src); } $(document).ready(function(){ $('#btnEnroll').on('click',function(){ var uname = $('#txtname').val(); var bError=false if (uname.length==0) { window.alert("Name is required.\\n") return false } if (uname.indexOf("\\\\")>=0) bError=true if (inStrGrp(uname,'/.:*?"<>| ')) bError=true if (bError) { window.alert('User name can not contain the following characters:\\n \\\\/. :*?"<>|\\n') return false } else var url = "enroll.asp?name="+uname; window.location = url; return true }); }); </script> 

change the url in the javascript code and put yours.If you url look like 更改javascript代码中的网址,然后输入您的网址。如果您的网址看起来像

http://10.11.201.170/data/sultan/enroll.asp http://10.11.201.170/data/sultan/enroll.asp

this then 然后这个

change the variable url in script section like the following 更改脚本部分中的变量URL,如下所示

var url = "http://10.11.201.170/data/sultan/enroll.asp?name="+uname;

and your enroll.asp will remain the same. 和您的enroll.asp将保持不变。

Hope that will help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM