带有链接的表单提交

发布于 2024-10-06 04:08:21 字数 831 浏览 0 评论 0原文

我正在用经典 ASP 构建一个网页,该网页最多包含 10 个包含在表单中的链接,并由 CSS 控制,以提供翻转和彩色块的外观。单击块/链接时,我需要向用户下载 Zip 文件,同时将表单提交回自身,以便可以使用此信息更新数据库。然后该页面可供用户下次下载。

我可以将 zip 文件下载到新窗口,但表单提交不一致,也许您可​​以提供建议。我在网上搜索了几周,但没有找到答案。

每个链接的构造如下

<table cellspacing="0" cellpadding="0" width="250" border="0">
     <form action="<%=request("script_name")%>" method="post" id="form1" name="form1">
          <tr style="height:18px;" bgcolor="#e8e8e8">
               <td bgcolor="#e6e6e6" align="center">
                    <a href="http://.....URL of Zip file" onClick="javascript:document.forms(0).submit();" class="dload">DOWNLOAD</a> 
                    <input type="Hidden" name="trak" value="1">
               </td>
          </tr>
     </form>
</table>

I am constructing a web page in classic ASP which has up to 10 links wrapped in forms and controlled by CSS to give a rollover and the appearance of a coloured block. When the block/link is clicked I need to download a Zip file to the user and at the same time submit the form back to itself so that a database can be updated with this information. The page would then be available for the next download by the user.

I can download the zip file to a new window but the form submits inconsistantly, perhaps you could advise. I have searched the web for a couple of weeks and not found an answer.

Each link is constructed as below

<table cellspacing="0" cellpadding="0" width="250" border="0">
     <form action="<%=request("script_name")%>" method="post" id="form1" name="form1">
          <tr style="height:18px;" bgcolor="#e8e8e8">
               <td bgcolor="#e6e6e6" align="center">
                    <a href="http://.....URL of Zip file" onClick="javascript:document.forms(0).submit();" class="dload">DOWNLOAD</a> 
                    <input type="Hidden" name="trak" value="1">
               </td>
          </tr>
     </form>
</table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

箜明 2024-10-13 04:08:21

使用 document.getElementById("form1").submit() 比假设此表单始终是文档中的第一个表单稍微稳健一些。我认为它的跨浏览器兼容性也更好一些。

Using document.getElementById("form1").submit() would be slightly more robust than assuming this form will always be the first in the document. I think it's slightly more cross-browser compatible, too.

忆依然 2024-10-13 04:08:21

试试这个:

<a href="http://.....URL of Zip file" 
     onClick="javascript:window.open(this.href); document.forms[0].submit();return false;" class="dload">DOWNLOAD</a>

Try this:

<a href="http://.....URL of Zip file" 
     onClick="javascript:window.open(this.href); document.forms[0].submit();return false;" class="dload">DOWNLOAD</a>
暖树树初阳… 2024-10-13 04:08:21

忘记表格。您正在进行日志记录,这对服务器来说并不是重大变化。将 ASP 切换为期望 GET 而不是 POST,然后只需执行以下操作:

<a href="<%=request("script_name")%>?trak=1">...</a>

让日志记录脚本返回 zip 文件(通过读取数据并直接返回它或使用 302 重定向进行响应)。

不要尝试让浏览器对一个链接发出两个 HTTP 请求,这样只会导致混乱。

Forget about forms. You are doing logging, that is not a significant change on the server. Switch the ASP to expect GET instead of POST then just do:

<a href="<%=request("script_name")%>?trak=1">...</a>

And have the logging script return the zip file (either by reading the data and returning it directly or responding with a 302 redirect).

Don't try to get the browser to make two HTTP requests for one link, that way just leads to a nasty mess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文